TorqueScript Reference
Functions
Random Numbers

Functions

Float getRandom ([min]?,[max]?)
 
Integer getRandomBell (min, max, [mean]?, [stdDev]?)
 
Float getRandomF (min, max)
 
Integer getRandomSeed ()
 
F32 mRandF (const F32 f1, const F32 f2)
 
S32 mRandI (const S32 i1, const S32 i2)
 
void setRandomSeed (startSeed)
 

Detailed Description

Function Documentation

◆ getRandom()

Float getRandom ( [ min ] ?  ,
[ max ] ?   
)

Use the getRandom function to get a random floating-point or integer value. This function comes in three forms. The first getRandom() takes no arguments and will return a random floating-point value in the range of 0.0 to 1.0. The second getRandom( max ) takes one argument representing the max integer value this will return. It will return an integer value between 0 and max. The third getRandom( min , max ) takes two arguments representing the min and max integer values this will return. It will return an integer value between min and max. Only the no-args version will return a floating point.

Parameters
minMinimum inclusive integer value to return.
maxMaximum inclusive integer value to return.
Returns
If no arguments are passed, will return a floating-point value between 0.0 and 1.0. If one argument is passed, will return an integer value between 0 and max inclusive. If two arguments are passed, will return an integer value between min and max inclusive.
See also
getRandomSeed

◆ getRandomBell()

Integer getRandomBell ( min  ,
max  ,
[ mean ] ?  ,
[ stdDev ] ?   
)

Gets a random integer number with normal distribution (a bell curve) from min to max with optional mean and standard deviation.

Parameters
minThe minimum range of the random integer number.
maxThe maximum range of the random integer number.
meanThe Most commonly occuring value or the center of the "bell". Must be between the min and max. Defaults to the center value between min and max.
stdDevThe standard deviation affects how far values tend to be from the mean. Defaults to 1/6th of the difference between min and max.
Returns
A random floating-point number from min to max.

◆ getRandomF()

Float getRandomF ( min  ,
max   
)

Gets a random floating-point number from min to max.

Parameters
minThe minimum range of the random floating-point number.
maxThe maximum range of the random floating-point number.
Returns
A random floating-point number from min to max.

◆ getRandomSeed()

Integer getRandomSeed ( )

Use the getRandomSeed function to get the current seed for the random generator. You can re-seed the generator with this value to allow you to recreate a random sequence. Merely save the seed and execute your random sequence. Later, to reproduce this sequence re-seed the generator with setRandomSeed and your saved value. Then, the generator will produce the same random sequence that followed the call to getRandomSeed.

Returns
Returns an integer value representing the current seed of the random generator.
See also
getRandom, setRandomSeed

◆ mRandF()

F32 mRandF ( const F32  f1,
const F32  f2 
)

◆ mRandI()

S32 mRandI ( const S32  i1,
const S32  i2 
)

◆ setRandomSeed()

void setRandomSeed ( startSeed  )

Use the setRandomSeed function to initialize the random number generator with the initial seed of startSeed.

Parameters
startSeedThe new starting seed value for the random generator.
Returns
No return value.
See also
getRandom, getRandomSeed