Torque 3D - Script Manual: Random Numbers

TorqueScript

Main   Class List   Namespace List   Online

Random Numbers
[Math]

Functions for generating random numbers. More...

Functions

float getRandom (int a, int b)
 Returns a random number based on parameters passed in..
int getRandomSeed ()
 Get the current seed used by the random number generator.
void setRandomSeed (int seed=-1)
 Set the current seed for the random number generator.

Detailed Description

Functions for generating random numbers.

Based on a seed, the random number generator produces a sequence of numbers. As a given seed will always produce the same sequence of numbers this can be used to generate re-producible sequences of apparently random numbers.

To set the seed, call setRandomSeed().


Function Documentation

float getRandom ( int  a,
int  b 
)

Returns a random number based on parameters passed in..

If no parameters are passed in, getRandom() will return a float between 0.0 and 1.0. If one parameter is passed an integer between 0 and the passed in value will be returned. Two parameters will return an integer between the specified numbers.

Parameters:
a If this is the only parameter, a number between 0 and a is returned. Elsewise represents the lower bound.
b Upper bound on the random number. The random number will be <= b.
Returns:
A pseudo-random integer between a and b, between 0 and a, or a float between 0.0 and 1.1 depending on usage.
Note:
All parameters are optional.
See also:
setRandomSeed
int getRandomSeed (  ) 

Get the current seed used by the random number generator.

Returns:
The current random number generator seed value.
void setRandomSeed ( int  seed = -1  ) 

Set the current seed for the random number generator.

Based on this seed, a repeatable sequence of numbers will be produced by getRandom().

Parameters:
seed The seed with which to initialize the randon number generator with. The same seed will always leed tothe same sequence of pseudo-random numbers. If -1, the current timestamp will be used as the seed which is a good basis for randomization.


Copyright © GarageGames, LLC. All Rights Reserved.