Main Index : Reference :

Random


Description

A pseudo random number generation class.

Definition

class Random
{
public:
  Random();
  
  [void] Init([int] seed);
  
  [float] Get01();  // Uniform between 0 and 1
  [float] Get11();  // Uniform between -1 and 1
  [float] GetG01(); // Gaussian between 0 and 1
  [float] GetG11(); // Gaussian between -1 and 1
}

Members

Init()

[void] Init([int] seed);

Initializes the pseudo random number sequence. The seed parameter must be between 0 and 2E9. Seeds that are close to each other, like 140 and 145, initially lead to similar random sequences. One can use the internal time() function as seed if one wants total randomness. However, it's often best to let the user specify the seed, so that the results are reproducable.


Get01()

[float] Get01();

Returns a uniformly distributed random value between 0 and 1.

Get11()

[float] Get11();

Returns a uniformly distributed random value between -1 and 1.


GetG01()

[float] GetG01();

Returns a random value between 0 and 1 with Gaussian distribution around 0.5. The standard deviation is 0.09.

GetG11()

[float] GetG11();

Returns a random value between -1 and 1 with Gaussian distribution around 0. The standard deviation is 0.18

Example

// Gets a random number between 0 and 1 and
// outputs it to the console:

var random = new(Random);
random->Init(8374946);

println(random->Get01());


// Throws a six-sided dice:

println("You threw a ", int(random->Get01() * 6 + 1));

See Also

Noise