random numer isn't random

# Thread: random numer isn't random

1. Gorillaz Guest

## random numer isn't random

hiya!<BR><BR>I&#039;m using this code to try to generate a random number between 1 and 4, and all I ever get back is 3.<BR><BR>Any ideas? Thanks!<BR><BR>&#039;random number generator<BR><BR>dim randomnum, b, a<BR><BR>b = 4.0 &#039;upperlimit<BR>a = 1.0 &#039;lowerlimit<BR>randomnum = int((b-a)*rnd+a+0.5)<BR><BR>Response.Write "<BR><BR>"<BR>Response.Write "&#060;p&#062;The random number is-&#060;/p&#062;"<BR>Response.Write randomnum

2. Junior Member
Join Date
Dec 1969
Posts
18

## RE: random numer isn't random

Try using the randomize function before using the Rnd function.

3. Gorillaz Guest

## RE: random numer isn't random

Can you show me some syntax to get started? Please? Thanks!

4. Senior Member
Join Date
Dec 1969
Posts
1,431

## RE: random numer isn't random

b = 4# &#039;upperlimit<BR> a = 1# &#039;lowerlimit<BR> randomnum = Int((b - a) * Rnd() + a + 0.5)<BR>

5. Gorillaz Guest

## RE: random numer isn't random

What&#039;s the change here? The #&#039;s give me an &#039;expected end of statement error&#039;.

6. Gorillaz Guest

## RE: random numer isn't random

This code seems to do what I want.<BR><BR>Dim MyValue <BR>Randomize &#039; Initialize random-number generator. <BR><BR>MyValue = Int((6 * Rnd) + 1) &#039; Generate random value between 1 and 6.<BR><BR>Thanks for the help.

#### Posting Permissions

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