# Random number problems?

## Recommended Posts

I want to get a random number between 1 and 3. When I use this script...

\$ran = Random ( 1,3 )

msgbox (0, "", "" & \$ran & "")

I ALWAYS get a long decimal number. How can I get it to be full numbers only? And how come I never had this problem before?

##### Share on other sites

Sorry... I figured it out... the script needs to look like this...

\$ran = Random ( 1,3 ) ;Get random number

\$ran2 = Round (\$ran) ;Round number to whole

msgbox (0, "", "" & \$ran & "") ;Output

Edited by mooboo

##### Share on other sites

think this is a better way:

```\$ran = int(Random (0,3 )+1)
msgbox (0, "", "" & \$ran & "")```

Your code will generate a number between 1.00000 and 2.9999999

1 - 1.499999 is rounded to 1

1.5 - 2.499999 is rounded to 2

2.5 - 2.999999 is rounded to 3

so theres a higher likelyhood that the result is 2 .... ( if i understand it correctly )

EDIT: come to think about it .. this should also work properly:

`\$ran = int(Random (1,4 ))`
Edited by JdeB

Live for the present,
Dream of the future,
Learn from the past.

## Create an account

Register a new account