class Random

A class providing various ways of generating pseudo random numbers.

Each instance uses its own private random seed and is therefore unaffected by other instances. By default, a simple linear noise (white noise) generator is used. However, if you wish you can pass a different type of NoiseGenerator to the constructor of this class.

Global Functions

float NewSeed ()Returns a floating-point value that can be used to initialize the random generator.

Constructors

Random ()Constructs a default random object with a private LinearNoise generator.
Random (float)Constructs a random object with a private LinearNoise generator.
Random (float, NoiseGenerator)Constructs a random object and passes a native object inheriting the NoiseGenerator interface.
Random (float, float, NoiseGenerator)Constructs a random object with a custom frequency.

Methods

int Chance (int)Returns randomly true or false.
float GetFloat ()Returns the next random value in the range 0.0 ~ 1.0.
float GetFloatMinMax (float, float)Returns the next random value in the range 'min' ~ 'max'.
float GetFloatRange (float)Returns the next random value in the range 0.0 ~ 'n'.
int GetIntMinMax (int, int)Returns the next random value as an integer in the range 'min' ~ 'max'.
int GetIntRange (int)Returns the next random value as an integer in the range 0 ~ 'n'.

Properties

float Frequency ()Returns the frequency, as specified in the constructor.
float Seed ()Returns the current random seed.

Reference

function float NewSeed ()

Returns a floating-point value that can be used to initialize the random generator.


method Random ()

Constructs a default random object with a private LinearNoise generator.

The random generator will be initialized with a seed of 0.


method Random (float seed)

Constructs a random object with a private LinearNoise generator.

The random generator will be initialized with the specified seed. When using the same seed, the generator will always create the same series of random numbers. You can use the result of the NewSeed() function if you want a different random series each time.


method Random (float seed, NoiseGenerator p)

Constructs a random object and passes a native object inheriting the NoiseGenerator interface.

Available noise generator classes are currently LinearNoise, QuadraticNoise, GaussianNoise, InterpolatedNoise and PerlinNoise.


method Random (float seed, float freq, NoiseGenerator p)

Constructs a random object with a custom frequency.

The frequency is the speed the seed advances after returning a new random number. By default, a frequency of 1.0 is used.


method int Chance (int percent)

Returns randomly true or false.

The higher the percentage value specified, the more likely this function will return true. A percentage of 0 will never return true, 100 will always return true.


method float GetFloat ()

Returns the next random value in the range 0.0 ~ 1.0.


method float GetFloatMinMax (float min, float max)

Returns the next random value in the range 'min' ~ 'max'.


method float GetFloatRange (float n)

Returns the next random value in the range 0.0 ~ 'n'.


method int GetIntMinMax (int min, int max)

Returns the next random value as an integer in the range 'min' ~ 'max'.


method int GetIntRange (int n)

Returns the next random value as an integer in the range 0 ~ 'n'.


accessor float Frequency ()

Returns the frequency, as specified in the constructor.


accessor float Seed ()

Returns the current random seed.