Random number

# Thread: Random number

1. Member
Join Date
Dec 1969
Posts
30

## Random number

How do I generate a random whole number between 2 values say 100 and 200?

2. Senior Member
Join Date
Dec 1969
Posts
5,104

## RE: Random number

Look up the RND() function.<BR><BR>-Doug

3. Member
Join Date
Dec 1969
Posts
49

## RE: Random number

The RND functions not actually much cop. This is a bit of vb I wrote which uses the date and time you run it to return a more randomized random number!<BR><BR>Public Function PickRandomNumber(Optional rnFrom As Integer, Optional rnLength As Integer)<BR><BR>&#039;############################ ###########<BR>&#039;APB Software - Random number generator<BR>&#039;Written by - Richard Burt<BR>&#039;Last change - 12/11/2001<BR>&#039;Notes:<BR>&#039;no paramaters passed will return 0 to 9 only<BR>&#039;rnFrom 0 = 0 to 9, rnfrom 1 = 1 to 10<BR>&#039;rnLength:If rnFrom = 0 then<BR>&#039; if rnlength = 0, 0 to 9<BR>&#039; if rnlength = 1, 0 to 99<BR>&#039; if rnlength = 2, 0 to 999<BR>&#039; If rnFrom = 1<BR>&#039; if rnlength = 0, 1 to 10<BR>&#039; if rnlength = 1, 1 to 100<BR>&#039; if rnlength = 2, 1 to 1000<BR>&#039;#################################### ###<BR><BR>Dim rott<BR><BR> Randomize<BR><BR> &#039;formula split because it kept returning error 13 at random?<BR><BR> rott = Str(Rnd * Now)<BR> rott = Val(Right(rott, 4 + rnLength))<BR> <BR> If rnFrom = 0 Then<BR> rott = (Int(rott / 1000))<BR> Else<BR> rott = (Int(rott / 1000)) + 1<BR> End If<BR> <BR> PickRandomNumber = rott<BR> <BR>End Function

4. Senior Member
Join Date
Dec 1969
Posts
5,104

?

5. Member
Join Date
Dec 1969
Posts
49

## RE: Why not Randomize Timer?

RND and Randomize don&#039;t actually produce random results(Computers are incapable).

6. Senior Member
Join Date
Dec 1969
Posts
5,104

## That's my point...

If you randomize against the timer (the # of milliseconds since midnight), that would give you as close to a random number as possible.<BR><BR>I was just asking, why go through your long function instead of just simply doing:<BR>Randomize Timer<BR><BR>Dim iRandom<BR> iRandom = Rnd(...random number range...)<BR><BR>-Doug

7. Senior Member
Join Date
Dec 1969
Posts
10,852

## Not entirely true.

Computers are incapable of producing a mathmatically generated random number....However, there are systems out there that can produce truly random numbers. <BR><BR>For instance....One uses a smapshot of the thermal signature being given off by the CPU heat sink at the time of the ramdomization call as the base for the generation.....Truly random.<BR><BR>Now...granted this has no bearing on your application, but I thought that I would point it out, just for the sake of it.<BR><BR>:-)

#### Posting Permissions

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