Random number generator (included): Difference between revisions

Added FutureBasic example
(Added FutureBasic example)
Line 314:
=={{header|Free Pascal}}==
FreePascal's function random uses the MersenneTwister (for further details, see the file rtl/inc/system.inc).
 
=={{header|FutureBasic}}==
<lang>
Syntax:
randomInteger = rnd(expr)
 
This function returns a pseudo-random long integer uniformly distributed in the range 1 through expr. The expr parameter should be greater than 1, and must not exceed 65536. If the value returned is to be assigned to a 16-bit integer (randomInteger), expr should not exceed 32767. The actual sequence of numbers returned by rnd depends on the random number generator's "seed" value. (Note that rnd(1) always returns the value 1.)
 
Syntax:
random (or randomize) [expr]
 
example: random 375 // using seed number
random // current system time used as seed
 
This statement "seeds" the random number generator: this affects the sequence of values which are subsequently returned by the rnd function and the maybe function. The numbers returned by rnd and maybe are not truly random, but follow a "pseudo-random" sequence which is uniquely determined by the seed number (expr). If you use the same seed number on two different occasions, you'll get the same sequence of "random" numbers both times. When you execute random without any expr parameter, the system's current time is used to seed the random number generator.
</lang>
Example:
To get a random integer between two arbitrary limits min and max, use the following statement. (Note: max - min must be less than or equal to 65536.):
<pre>
randomInteger = rnd(max - min + 1) + min - 1
</pre>
To get a random fraction, greater than or equal to zero and less than 1, use this statement:
<pre>
frac! = (rnd(65536)-1)/65536.0
</pre>
To get a random long integer in the range 1 through 2,147,483,647, use this statement:
<pre>
randomInteger& = ((rnd(65536) - 1)<<15) + rnd(32767)
</pre>
 
=={{header|GAP}}==
729

edits