Page 1 of 1

How to make random numbers?

Posted: Fri Jun 23, 2006 8:49 am
by Mark Fulford
I want three random numbers from my script in the range 0 to 50000 that are different each time the script is run on the same PC.

I am generating the number as follows:
RANDOM1 = Generate Random Number (max value 50000)
RANDOM2 = Generate Random Number (max value 50000)
RANDOM3 = Generate Random Number (max value 50000)

These are sample results:
RANDOM1 = 2400
RANDOM2 = 700
RANDOM3 = 1300

RANDOM1 = 4300
RANDOM2 = 2700
RANDOM3 = 4700

RANDOM1 = 1400
RANDOM2 = 2900
RANDOM3 = 3500

Clearly I've got something wrong, but what?

Posted: Fri Jun 23, 2006 1:23 pm
by Gizm0
And what is the actual result?

Posted: Fri Jun 23, 2006 3:04 pm
by MichaelNesmith
I believe the max of this function is 32767, in case that is what's bothering you with the results.

Posted: Fri Jun 23, 2006 3:43 pm
by Gizm0
Yes, the MAX_INT value on Windows is 32767..If you want more, you have to multiply it, or create a custom dll and get the result from there!

Posted: Mon Jun 26, 2006 3:14 am
by Mark Fulford
The help file does not give sufficient detail of functions such as this. For example, what are the purposes of the two seed parameters?

Posted: Mon Jun 26, 2006 5:26 pm
by MichaelNesmith
They seed the random number generator with the specified number. Each seed must be unique for the random number generation to be truly pseudo-random. Please see the Serial Validation example project for detailed real-world usage of these functions.

Posted: Tue Jun 27, 2006 3:14 am
by Mark Fulford
What I'm getting at is that the Help file is a bit light. For each function it should include information about parameters and results, such as the limit to the size of a random number and the range for seeds. A worked example within the Help file would also be quite normal.