Results 1 to 9 of 9

Thread: Unsigned Long random number help

Threaded View

  1. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Unsigned Long random number help

    A simpler version, to the ticks
    Code:
     Private rng As New Random
        Private Function PickRandomDateBetween(ByVal fromDate As Date, ByVal toDate As Date) As Date
            Dim multiplier As Double = rng.NextDouble
            Do Until (multiplier > 0.0R)
                multiplier = rng.NextDouble
            Loop
            Return fromDate.AddTicks(CLng(multiplier * toDate.Subtract(fromDate).Ticks))
        End Function
    Per ForumAccount's suggestion in post#7, I've change the loop to test just if NextDouble > 0 since the return value is alreay always < 1.
    I also changed the literal type character from D to R (for some reason, I keep mixing those up )
    Last edited by stanav; Jul 20th, 2011 at 09:52 AM. Reason: ETo conform to ForumAccount's suggestion in post #7 below.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width