Using a random number, generate a date and time within the total time range. When you finish setting up random beeps, then the intervals will, of course, be random. Something like that:
List<DateTime> randomBeeps = new List<DateTime>(); Random rand = new Random(); for( int j = 0; j < numberBeepsNeeded; j++ ) { int randInt = rand.Next(); double percent = ((double)randInt) / Int32.MaxValue; double randTicksOfTotal = ((double)setAmountOfTime.Ticks) * percent; DateTime randomBeep = new DateTime((long)randTicksOfTotal); randomBeeps.Add(randomBeep); }
You may need to use Convert.ToLong or something like that. Not sure if this will give you an error when converting from double to long, as it rounds it off, which is good here.
source share