Random Numbers

1. Senior Member
Join Date
Dec 1969
Posts
213

## Random Numbers

I was looking though my "Sam&#039;s Teach your self ASP 3.0 in 21 days" for a way to generate a random 9 digit number. Now I saw the randomize() function but I don’t quite understand how to use it (or even it can be used for what I want). Can someone help me generate a random 9 digit number?

2. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: Random Numbers

The randomize function doesn&#039;t return a random number, it &#039;resets&#039; the number the rnd() function returns<BR><BR><BR>from the docs: (you do have a copy of the official docs don&#039;t you? If not you can use the msdn.microsoft.com site. )<BR><BR>Rnd Function<BR><BR>Returns a Single containing a random number.<BR><BR>Syntax<BR><BR>Rnd[(number)]<BR><BR>The optional number argument is a Single or any valid numeric expression.<BR><BR>Return Values<BR><BR>If number is Rnd generates <BR>Less than zero The same number every time, using number as the seed. <BR>Greater than zero The next random number in the sequence. <BR>Equal to zero The most recently generated number. <BR>Not supplied The next random number in the sequence. <BR><BR><BR>Remarks<BR><BR>The Rnd function returns a value less than 1 but greater than or equal to zero.<BR><BR>The value of number determines how Rnd generates a random number:<BR><BR>For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.<BR><BR>Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.<BR><BR>To produce random integers in a given range, use this formula:<BR><BR>Int((upperbound - lowerbound + 1) * Rnd + lowerbound)<BR><BR>Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.<BR><BR>Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.<BR><BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
213

## So like this?

So if I wanted to get a random 9 digit number I would do this:<BR><BR>Int((999999999 - 000000000 + 1) * Rnd + 000000000)

4. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: So like this?

don&#039;t forget to call randomize before your function.<BR><BR>Radomize Timer<BR>randcomnumber = Int((999999999 - 000000000 + 1) * Rnd + 000000000)<BR><BR><BR>(keep in ming though, computers *always* generate semi-random numbers)

#### Posting Permissions

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