Random Numbers - SFMT
SFMT is a new variant of Mersenne Twister, a pseudorandom number generator.
This is a cross-platform BlitzMax implementation of SFMT.
Apart from Rand64, the module function names are the same as the BRL.Random functions, which should allow for this module to be used as a drop-in replacement. (It's up to the developer to sort out Framework/Import issues)
The SFMT module is also generally faster than the equivalent BRL.Random functions.
Usage
Before using any of the number generation functions, you need to initialize the internal 'state' array by first calling SeedRnd. Also, if you want to mix use of Rand64 and Rand, you will need to re-initialize the state array before the call to the function.
Functions Summary
| Rand |
Generate random 32-bit integer.
|
| Rand64 |
Generate random 64-bit Long.
|
| Rnd |
Generate random double.
|
| RndDouble |
Generate random double.
|
| RndFloat |
Generate random float.
|
| SeedRnd |
This function initializes the internal state array with a 32-bit integer seed.
|
Functions
| Function Rand:Int( min_value:Int, max_value:Int = 1 ) |
| Returns | A random 32-bit integer in the range min (inclusive) to max (inclusive) |
| Description | Generate random 32-bit integer. |
| Information | You should call SeedRandom to initialize the pseudorandom number generator, before calling this function
for the first time.
The optional parameter allows you to use Rand32 in 2 ways:
| Format | Result |
| Rand32(x) | random 32-bit integer in the range 1 to x (inclusive) |
| Rand32(x,y) | random 32-bit integer in the range x to y (inclusive) |
|
| Function Rand64:Long( min_value:Long, max_value:Long = 1 ) |
| Returns | A random 64-bit Long in the range min (inclusive) to max (inclusive) |
| Description | Generate random 64-bit Long. |
| Information | You should call SeedRandom to initialize the pseudorandom number generator, before calling this function
for the first time, or if you have used Rand32 previously.
The optional parameter allows you to use Rand64 in 2 ways:
| Format | Result |
| Rand64(x) | random 64-bit Long in the range 1 to x (inclusive) |
| Rand64(x,y) | random 64-bit Long in the range x to y (inclusive) |
|
| Function Rnd:Double( min_value!=1,max_value!=0 ) |
| Returns | A random double in the range min (inclusive) to max (exclusive) |
| Description | Generate random double. |
| Information | The optional parameters allow you to use Rnd in 3 ways:
| Format | Result |
| Rnd() | random double in the range 0 (inclusive) to 1 (exclusive) |
| Rnd(x) | random double in the range 0 (inclusive) to n (exclusive) |
| Rnd(x,y) | random double in the range x (inclusive) to y (exclusive) |
|
| Function RndDouble:Double() |
| Returns | A random double in the range 0 (inclusive) to 1 (exclusive) |
| Description | Generate random double. |
| Function RndFloat:Float() |
| Returns | A random float in the range 0 (inclusive) to 1 (exclusive) |
| Description | Generate random float. |
| Function SeedRnd(seed:Int) |
| Description | This function initializes the internal state array with a 32-bit integer seed. |
Module Information
| Version | 1.00 |
| Author | Mutsuo Saito, Makoto Matsumoto |
| License | BSD |
| Credit | Adapted for BlitzMax by Bruce A Henderson |
| Modserver | BRL |
| History | 1.00 |
| History | Initial Version (SFMT 1.2) |
| CC-OPTS | -DMEXP=19937 |
| CC-OPTS | -fno-strict-aliasing |
| CC-OPTS | -DALTIVEC=1 |
| CC-OPTS | -faltivec |