I'm trying to generate random dates in between two dates that are selected with a date and time selection control.
Ideally, I would like to get the 'ticks' of each date, generate a random number between those, and then convert that back into a date.
However I'm getting arithmetic overflow errors when I try to generate a random number from the between the ticks. I've tried many approaches - directly seeding with both the low and high date ticks, as well as subtracting.
Code:Private Function randomDate() As ULong Dim rand As New Random(Date.Now.Ticks Mod Integer.MaxValue) Dim holder As ULong = DateTimePicker2.Value.Ticks - DateTimePicker1.Value.Ticks return rand.Next(holder)Code:Private Function randomDate() As ULong Dim rand As New Random(Date.Now.Ticks Mod Integer.MaxValue) return rand.Next(DateTimePicker1.Value.Ticks, DateTimePicker2.Value.Ticks)




Reply With Quote
