Link to home
Start Free TrialLog in
Avatar of Jodah
Jodah

asked on

How to make a REAL random number...

Trying to create a totally randomized dice-roller program. On program load, numbers are always the same, i nthe same order (i.e.-  first roll 15, second 8, third 6, etc...) using this code...

Public Sub d20(ByVal X)
X = Int(Rnd * 20)
End Sub

Any ideas?
Avatar of List244
List244

Use Randomize

Public Sub d20(ByVal X)
Randomize
X = Int(Rnd * 20)
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Chuckie_Ice
Chuckie_Ice

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
X = round((Rnd * 20) + .5)
if the rnd part doesn't work you have a problem!

test it
for y = 1 to 10
msgbox ( Rdn)
next y
Public Sub d20(ByVal X)
       Randomize Timer
       X = Int(Rnd * 20)+ 1 '+1 means you get 0
End Sub
'slight typo with the last post...

      Randomize Timer
      X = Int(Rnd * 20)+ 1 '+1 means you wont get 0
jpwiedenhoff,
Not strictly true, rnd always returns the median number, you need to use the randomize command a la List244 et al to get it to give properly random numbers from the range 8-P
OK your right. didn't noticed that before. my applications were written in a way which must have somehow provided that even If  I didn't noticed that yet. But live is for learning or?
Avatar of Jodah

ASKER

Thanks. Got it running smoothly now :).