I am creating a test file and I need to fill it with random times between 7AM to 11AM. Repeating entries are OK as long as they aren't all the same
I'm also only interested in HH:MM (no seconds)
I don't know where to start. I did Google before posting and I found an interesting search result
www.random.org/clock-times/
Only issue is that all times "randomly" generated are in sequential order. I can put it out of sequence once but I need to generate 100 to 10,000 entries.
I am hoping to create a WinForm C# app that will help me do this.
The number
14400
is the number of seconds between 7 AM and 11 AM, which is used as the basis for random number generation.The
randomTimes
list can be used with DateTime formatting to achieve the desired output format, like:A simple option (picking the hour and minute as random
ints
):Create a
DateTime
value for the lower bound, and a random generator:Now you can create random times by adding minutes to it:
To format it as HH:MM you can use a custom format: