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.
Calculate the number of minutes between your start and stop times then generate a random number between 0 and the maximum number of minutes:
Notes:
Here is a generic method to give you a random date between a given start and end date.
If you use something like this a lot you could make it an extension method on
Random
.Maybe I am missing something but isn't it as simple as this...
If you wanted to make it simplier to understand the numbers you could expand it out....
Something like this:
Throwing my hat in the ring :)
Edit: It's slightly embarrassing to see so many answers for effectively is a dead simple question. Anyway, nice to see different styles. Reading the question I was surprised to see the OP ask to create Win Forms app to do this. The task seemed so straight forward, I wanted to write the solution in LinqPad!
Create a
Random
object and use that to create a newDateTime
Then use the time output where you want it.