Random Numbers

R

requeth

Hello,

I'm having an issue with random number generation. I am trying to run
the following, but out of 14 times it's generated the same number 12
times, which so happens to be 7563.

randwork1 = Int((9 * Rnd) + 1)
randwork2 = Int((9 * Rnd) + 1)
randwork3 = Int((9 * Rnd) + 1)
randwork4 = Int((9 * Rnd) + 1)
randnumber = randwork1 & randwork2 & randwork3 & randwork4


I thought perhaps since I was running it in an onclick function that
it was somehow caching the results. But reopening the form does not
help. I tried placing it into a macro and trying to pass the variable
back like so:

randnumber = keygen(randnumberfin)

but that gave me a type mismatch though everything is an int.

All I'm trying to get is a 4 digit random number that's random enough
that it has a low probability of duplicating out of 30 consectutive
tries. Any ideas why it is giving me the same number?
 
D

Douglas J. Steele

Before using the Rnd statement, you need to use the Randomize statement to
minimize the chance of repetition.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top