BaH.Random: Functions Modinfo Source  

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 )
ReturnsA random 32-bit integer in the range min (inclusive) to max (inclusive)
DescriptionGenerate random 32-bit integer.
InformationYou 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:
FormatResult
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 )
ReturnsA random 64-bit Long in the range min (inclusive) to max (inclusive)
DescriptionGenerate random 64-bit Long.
InformationYou 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:
FormatResult
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 )
ReturnsA random double in the range min (inclusive) to max (exclusive)
DescriptionGenerate random double.
InformationThe optional parameters allow you to use Rnd in 3 ways:

FormatResult
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()
ReturnsA random double in the range 0 (inclusive) to 1 (exclusive)
DescriptionGenerate random double.

Function RndFloat:Float()
ReturnsA random float in the range 0 (inclusive) to 1 (exclusive)
DescriptionGenerate random float.

Function SeedRnd(seed:Int)
DescriptionThis function initializes the internal state array with a 32-bit integer seed.

Module Information

Version1.00
AuthorMutsuo Saito, Makoto Matsumoto
LicenseBSD
CreditAdapted for BlitzMax by Bruce A Henderson
ModserverBRL
History1.00
HistoryInitial Version (SFMT 1.2)
CC-OPTS-DMEXP=19937
CC-OPTS-fno-strict-aliasing
CC-OPTS-DALTIVEC=1
CC-OPTS-faltivec