Random module

The random module contains basic functions to generate pseudorandom numbers. LSP uses the Mersenne Twister algorithm as its core generator. It has a long period of 2^19937 − 1.

Note

To use the features of this module, you have to put a special import statement at the begining of your LSP file: use random;

Module functions

Before using any of the functions below, you have to create a random instance with the create() function.

random.create()
random.create(seed)

Creates a new random generator with the given seed. The seed is optional. If seed is omitted, the current system time is used to initialize the generator.

Parameters:

int (seed) – Seed to initialize the pseudorandom generator.

Return type:

Random

Classes

class Random
init()
init(seed)

Re-initializes the random generator with the given seed or a new seed. The seed is optional. If seed is omitted, the current system time is used to initialize the generator.

next(b)
next(a, b)

Returns the next random integer N such that a <= N < b for a <= b and b < N <= a for b < a. The generated numbers are uniformly distributed between the open range induced by a and b.

Return type:

int

nextUniform(min, max)

Returns the next floating point number N such that a <= N < b for a <= b and b < N <= a for b < a. The generated numbers are uniformly distributed between the open range induced by a and b.

This method generates floats with 52 bits of precision on the mantissa.

Return type:

double

nextNormal()
nextNormal(mu, sigma)

Normal distribution.

Parameters:
  • mu (double) – Mean of the normal distribution

  • sigma (double) – Standard deviation.

nextLogNormal()
nextLogNormal(mu, sigma)

Log normal distribution.

Parameters:
  • mu (double) – Mean of the normal distribution

  • sigma (double) – Standard deviation. Must be greather than 0.