How to generate n random dates between 2 time periods

Hi,
I'm trying to write a method that generates n random dates between 2
time periods. For example, lets say I want to generate n random dates
between Jan 1 2003 and Jan 15 2003. I'm not sure how to go about
doing the random date generation. Can someone provide some direction
on how to do this?
The method signature should look like this.
public String[] generateRandomDates(String date1,String date2,int n){
// date1 and date2 come in the format of mmddyyyyhh24miss.
// n is the number of random dates to generate.
return dateArray;
Thanks.
Peter

first take a look at the API concerning a source of randomness (Random might be a good guess), then take a look at stuff concerning dates (Date might be cool, maybe you will find some links from there).
Who wrote this stupid assignment?

Similar Messages

  • How to generate n random dates

    Can anyone help me in generating Random dates, i want to generate 100 random dates in yyyy-mm-dd format.

    I've tried this, but will appreciate any neat solutions...
    public static void main(String arg[]) {
        int no = 0;
        while (no < 100) {
          // Year
          int yylower = 1970; // your lower integer value
          int yyupper = 2000; // the larger one of your two integers
          double rand = Math.random();
          int yyresult = yylower + (int) ( (yyupper - yylower) * rand);
          // Month
          int mmlower = 1; // your lower integer value
          int mmupper = 12; // the larger one of your two integers
          rand = Math.random();
          int mmresult = mmlower + (int) ( (mmupper - mmlower) * rand);
          // Month
          int ddlower = 1; // your lower integer value
          int ddupper = 29; // the larger one of your two integers
          rand = Math.random();
          int ddresult = ddlower + (int) ( (ddupper - ddlower) * rand);
          System.out.println(yyresult  + "-" + mmresult + "-" + ddresult);
          no++;
      }

  • How to Build a VI that generates a random number between 1 and 80 ....Help!!!!

    Build a VI that generates a random number between 1 and 80 
    Divides the random number by a number specified in the front panel.
    If the inputted number is zero, the VI program should turn on a LED in the front-panel to indicate a divide by zero error.
    Solved!
    Go to Solution.

    One quick question Edward, was the answer just in time for your monday morning class.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • How can I print the date and time in a photo from iPhoto

    How can I print the date and time in a photo from iPhoto

    You want to print them on their own? Can't be done. WIth the photo? Install this
    http://www.iborderfx.com/iborderfx/

  • How do I remove a date and time mark on a stored photo so I can put it into a calendar

    How do I remove a date and time mark on a stored photo so I can put it into a calendar.....?

    In Iphoto, yes.  You can use PhotoShop Elements or some other editor.  You can also crop.  (You might be able to make the retouch brush smaller.)

  • How do I find the date and time stamp on pictures?

    How do I find the date and time stamp for my pictures?

    The Photos app will not do this but other apps will. iPhoto has an icon that when tapped with the photo open will show the EXIF information you are looking for. iPhoto is not free but you can purchase it in the App Store.
    There may be other photo apps that provide this information as well.
    PhotoForge2 will show the EXIF data as well as the GPS data if it is available.

  • How can I copy the date and time in Mail header?

    How can I copy the date and time in Mail header?
    I can copy everything else in the header for pasting in another application. 
    But not the date and time which is absolutely vital.
    It was ok in 10.6 

    I suppose you could copy it from the Raw Source. View>Message>Raw Source

  • Urgent How to generate a random code such as registration code?

    I would like to ask that how to generate a random code?
    For example, when you register a E-mail account, you need to enter the code for activation. I would like to create a java Bean to do this job. Would you help me?

    In fact, I would like to set a 10 digi codes randomly (such as FH654CS081, MKO624VG9f) for user input when they register the forum account. This random code will be sent to the user's email. User have to input this code to a JSP web site. Also, the code which is inputed by user will be matched with the database. If user input success, the forum account will be activated.
    By generating this 10 digi codes, I want to handle this generation by using java bean.
    1) Any thing else i need to import ? (such as <% page import="java.......?")
    2) Any functions can handle this task?
    3) Any example can be my reference?
    Thank you very much

  • How can I get the date and time and display it on the report main page?

    Gurus,
    How can I get the date and time and display it on the report main page?
    Thanks!

    Hello,
    You can create a Formula Colum returning a date :
    function CF_1Formula return Date is
    begin
    RETURN(SYSDATE);
    end;
    Put a Field in the Layout having this formula column as source .
    Regards

  • How to generate a random session variable in php

    i want to generate a random session variable and insert the variable in a mysql record to use later to validate an account set up.
    person fills out form to create account and submits; inserts form information in mysql record.
    i want the random variable to be inserted from a hidden field and the page sends an email with a link to click on to compare the variable to validate the user.
    Not sure how to generate a random session variable and get that to the hidden field value to be inserted with the other form information.
    thanks for your help,
    Jim Balthrop

    To insert the key I would personally do something like...
    $key = md5($username . $password . $salt);
    Insert that into your MySQL database, then send them a email with it, my next code shows how to activate it.
    This is to activate the account.
    <?php
    $key;
    $errors = array();
    if(isset($_GET['key']){
         $key = $_GET['key'];
         $sql = 'SELECT * FROM users WHERE key = \'' . $key '\' LIMIT 1';
         $result = mysql_query($sql) or die(mysql_error());
         if(mysql_num_rows($result)){
              $sql2 = 'UPDATE users SET active = 1 WHERE key = \'' . $key '\' LIMIT 1';
              $result2 = mysql_query($sql2) or die(mysql_error());
              if($result2){
                   //successfully activated account
              else{
                   //Something Went Wrong!
         else{
              $errors[] = 'Invaild Key, Please try again!';
    else{
         $errors[] = 'Invaild Key, Please try again!';
    ?>

  • HOW DO I ACCESS PICTURE DATE AND TIME?

    HOW DO I ACCESS PICTURE DATE AND TIME ON A IPHONE 4?

    There may be a 3rd party app that provides for this. Apple's iPhoto iOS app provides this data.

  • HT2305 how can I correct my date and time on my 3G?

    How can I correct my date and time on my 3G? Thanks in advance!

    Just trying to go along the free route. I found Garage Buy   This doesn't work to well but lets you create an applescript and enters the auction into ical. Then you can set ical to run the script once it gets closer to the time.
    Ical only lets you set a time of a minute before the date. So you have to edit the script to add a Delay 59 to have it run 1 second before. From a few refreshes of the time page it looks like ebay time is a second behind, that could be easily be due to time to load the page. anyway i'll opt for a delay of 57secs and give that a try.

  • Query to search between two specific dates and time period

    Hi,
    Need a query to search between two particular dates and time period
    Like i want to search table having one date field .
    Suppose the date range is '01-JUL-06' and '01-AUG-06' and time frame
    is 23:00:00 to 08:00:00
    i.e i want to search between dates 01 july to 01 aug and also within the time frame i.e 23:00 to 08:00 hrs only

    The general principle is
    SELECT * FROM your_table
    WHERE some_date BEWTEEN to_date('01-JUL-06') and to_date('01-AUG-06' )+0.99999
    AND  ( some_date <= trunc(some_date)+8/24
               OR  some_date >= trunc(some_date)+23/24 )
    /Cheers, APC

  • How can I  get System dates  with time scheduler using threads

    how can I get System dates with time scheduler using threads.is there any idea to update Date in my application along with system Date automatic updation...

    What the heck are you talking about and whatr has it to do with threads?
    Current time: System.currentTimeMillis. Date instances are not supposed to be updated.

  • How to generate unique random numbers

    Hi All,
    I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
    Random diceRoller = new Random();
    for (int i = 0; i < 10; i++) {
      int roll = diceRoller.nextInt(6) + 1;
      System.out.println(roll);
    }My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
    Using the above example to illustrate my intention:
    1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
    2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
    3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
    4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
    5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
    Any assistance would be much appreciated.
    Many thanks,
    Jack

    htran_888 wrote:
    Hi All,
    I am wondering whether there is already a random library or built-in function available in Java to produce some random numbers between certain ranges that are not repetitive. Let's look at a common examples as follows:
    Random diceRoller = new Random();
    for (int i = 0; i < 10; i++) {
    int roll = diceRoller.nextInt(6) + 1;
    System.out.println(roll);
    }My understanding from this approach is that it allows the same number to be repeated over and over again. However, I would like to find out how to continue generating random numbers from remaining ones that haven't been generated earlier.
    Using the above example to illustrate my intention:
    1st random number generated - possibility of 1 - 6 showed up. Say 5 is picked.
    2nd random number generated - possibility of 1, 2, 3, 4, 6 only. Say 2 is picked.
    3rd random number generated - possibility of 1, 3, 4, 6 available. Say 1 is picked.
    4th random number generated - possibility of 3, 4, 6 left. Say 6 is picked.
    5th random number generated - possibility of 3, 4 remains. Say 4 is picked.
    Any assistance would be much appreciated.If it is your school assignment then you have the answer above (List & the lists length).
    (You might want to look at Collections)

Maybe you are looking for

  • Is it my updated Firefox that is causing my PC (Windows XP) to freeze every time I attempt to do daily Ad-Aware updates?

    Ad-Aware (Lavasoft) ran smoothly on my PC (Windows XP) until the latest Firefox update. Now my PC freezes when I attempt the daily Ad-Aware update. I have to turn off the power supply to my PC to reboot. I have uninstalled Ad-Aware and attempted to r

  • Trying to access Music Store and iTunes shuts down...

    I've been trying to open the Music Store for days with no luck. I get an error message "The exception Privileged instruction 0xc0000096 occurred in the application at location 0x1003527a" and when I click "ok" iTunes closes abruptly. Sometimes I don'

  • Adobe problem when opening PSD registration

    Hello, I have a big problem in my adobe software (Photoshop and Fireworks by-example). When, for example, I backup my project psd, short layers that I did well at the opening of what I save almost all my layers are disorders ... They are displaced, s

  • Unbekanter Fehler in Camera Raw 6.7.1

    Guten Tag, Ich verwende einen Windows 7 64 Bit und die CS 5.5. Unter Bridge/ Camera Raw 6.7.1 kommt einen "unbekannter Fehler" beim speichern die Dateien. Kenn jemand eine Lösung? Freundliche Grüsse

  • Getting rid of unwanted software

    Hello there, I use an ibook G4 and my computer only came with a 60GB HD. I have an external hard drive on which I keep my music and photos. The purpose of this post is that I'm looking for a nice way to be able to view all the files on my G4 and sort