Results 1 to 10 of 10

Thread: Random Time Between Fixed Lower And Upper Limits

  1. #1
    Member
    Join Date
    Nov 2012
    Posts
    33
    Rep Power
    0

    Random Time Between Fixed Lower And Upper Limits

    I've been able to create random numbers, but I cannot create random times. For example, I want to create a schedule of training and use random times to call the group together (between 6:30 and 9:00, or between 11:45 and 2:00). Is there any formula to do this?

    Thanks

  2. #2
    Junior Member
    Join Date
    Jun 2013
    Posts
    13
    Rep Power
    0
    Quote Originally Posted by papabill View Post
    I've been able to create random numbers, but I cannot create random times. For example, I want to create a schedule of training and use random times to call the group together (between 6:30 and 9:00, or between 11:45 and 2:00). Is there any formula to do this?
    Thanks
    Have you tried creating random numbers and adding them to your start times with TimeSerial() ?


    Edit: Tested it, and it was better to use just one random number and figure the minutes between your times. 6:30 to 9:00 would be 150minutes.

    Edited code:
    Code:
    Dim randomminute As Integer
    Dim StartTime1 As String
    
        StartTime1 = "6:30 AM"
        
        randomminute = Int((150 - 0 + 1) * Rnd + 0)
        ActiveCell.Value = StartTime1
        ActiveCell.Value = ActiveCell.Value + TimeSerial(0, randomminute, 0)
        ActiveCell.NumberFormat = "hh:mm am/pm"
    Last edited by testingcode; 07-19-2013 at 07:54 PM.

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    testingcode, you could limit the lines to this

    Code:
    ActiveCell.Value = TimeValue("06:30:00") + TimeSerial(0, Int((150 - 0 + 1) * Rnd + 0), 0)
    However, OP wanted to include two time ranges.

    Here's one way to do that

    Code:
            Randomize
            If Rnd > 0.5 Then
                ActiveCell.Value = (TimeValue("09:00:00") - TimeValue("06:30:00") + 0.0001) * Rnd + TimeValue("06:30:00")
            Else
                ActiveCell.Value = (TimeValue("14:00:00") - TimeValue("11:45:00") + 0.0001) * Rnd + TimeValue("11:45:00")
            End If
    Having said that, since the original request was for a formula, this should suffice

    =IF(RAND()<0.5,TIME(6,RANDBETWEEN(30,180),0),TIME( 11,RANDBETWEEN(45,180),0))
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  4. #4
    Junior Member
    Join Date
    Jun 2013
    Posts
    13
    Rep Power
    0
    Still learning. Also didn't see the formula part

  5. #5
    Member
    Join Date
    Nov 2012
    Posts
    33
    Rep Power
    0
    That seems to work well, but the products are very random. I still need to control them.

    How do I put it so it will give me times between 6 - 9am, 11am - 2pm, 6pm - 8pm, and 11pm - 12:30am
    Code:
    Day          Stretches     Running warmups     Pulls          Pushes
    Mon          6:30am            11:15am            6:15pm      11:30pm
    Tue          8:00am             1:30pm            7:20pm      11:15pm
    Wed         etc.                   etc.                etc.           etc.
    Times are changing due to other activities and training.

  6. #6
    Junior Member
    Join Date
    Jun 2013
    Posts
    13
    Rep Power
    0
    Are you wanting 6-9am in the Stretches column, 11am-2pm in the Running warmups column, ect..?

    If so, then you can just use the
    Code:
    =TIME(6,RANDBETWEEN(0,180),0)
    in the correct column and adjust the bolded numbers to whatever time frame is needed for that column. The example formula above would be for the Streches column.
    Last edited by testingcode; 07-19-2013 at 11:25 PM.

  7. #7
    Member
    Join Date
    Nov 2012
    Posts
    33
    Rep Power
    0
    Thanks to all you for the help. Now I can create a good schedule.

  8. #8
    Member
    Join Date
    Nov 2012
    Posts
    33
    Rep Power
    0
    Quote Originally Posted by testingcode View Post
    Code:
    =TIME(6,RANDBETWEEN(0,180),0)
    Can you explain something for me? I understand MOST of the formula, but not all. =TIME(6,RANDBETWEEN(0,180),0)

    I understand the 6 (6 oclock) and the 180 (180 minutes-three hours past 6 = 9), but what about the 0 in (0,180)?

    Thanks

  9. #9
    Junior Member
    Join Date
    Jun 2013
    Posts
    13
    Rep Power
    0
    Quote Originally Posted by papabill View Post
    Can you explain something for me? I understand MOST of the formula, but not all. =TIME(6,RANDBETWEEN(0,180),0)

    I understand the 6 (6 oclock) and the 180 (180 minutes-three hours past 6 = 9), but what about the 0 in (0,180)?

    Thanks
    RANDBETWEEN(0,180) means that it picks a random number between 0 and 180. 0 is your lower bound and 180 is your upper. For example, a RANDBETWEEN(10,180) would never return a 1, 2, or 3, ect..

  10. #10
    Member
    Join Date
    Nov 2012
    Posts
    33
    Rep Power
    0
    I understand now, thanks.

Similar Threads

  1. Custom Charts in Excel :: Comparison RAG Chart Showing Tolerance Limits
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 06-13-2013, 09:40 PM
  2. Calculate Time Difference Between Time In HH:MM
    By Stalker in forum Excel Help
    Replies: 8
    Last Post: 03-28-2013, 03:27 PM
  3. Fixed asset Register
    By Howardc in forum Excel Help
    Replies: 1
    Last Post: 11-14-2012, 10:20 AM
  4. Reverse name in excel with upper case,edit formula
    By shrinivasmj in forum Excel Help
    Replies: 3
    Last Post: 09-11-2012, 01:31 PM
  5. Spreading a time range (shift time, etc) in columns.
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 1
    Last Post: 08-23-2011, 11:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •