Cerberus X Documentation

Module cerberus.random

The random module provides functions to generate random numbers. More...

Declarations

Imported By
cerberus
Please note that only documented modules are listed here, there might be undocumented modules that import this one.
Globals
Seed : Int The current random number generator seed used by Rnd.
Functions
Rnd : Float () Returns a random float in the range 0 (exclusive) to 1 (exclusive).
Rnd : Float ( range:Float ) Returns a random float in the range 0 (exclusive) to range (exclusive).
Rnd : Float ( low:Float, high:Float ) Returns a random float in the range low (exclusive) to high (exclusive).

Detailed Discussion

The random module provides functions to generate random numbers.

Print Rnd() ' anything between 0.0 and 1.0
Print Int(Rnd(10)) ' any integer from 0 to 9
Print Int(Rnd(5,10)) ' any integer from 5 to 9
Print (Int(Rnd(21))-10) ' any integer from -10 to 10

Globals Documentation

Global Seed : Int

The current random number generator seed used by Rnd.

A common way to initialize seed is to use the current system time, so the random number generator always generates different sequences after every start up:

Local date := GetDate()
Seed = date[3] * 3600000 + date[4] * 60000 + date[5] * 1000 + date[6]
See also

Rnd


Functions Documentation

Function Rnd : Float ()

Returns a random float in the range 0 (exclusive) to 1 (exclusive).

Print Rnd() ' anything between 0.0 and 1.0
Print Int(Rnd()) ' always 0
See also

Seed

Function Rnd : Float ( range:Float )

Returns a random float in the range 0 (exclusive) to range (exclusive).

Print Rnd(10) ' anything between 0.0 and 10.0
Print Int(Rnd(10)) ' any integer from 0 to 9
See also

Seed

Function Rnd : Float ( low:Float, high:Float )

Returns a random float in the range low (exclusive) to high (exclusive).

Print Rnd(5,10) ' anything between 5.0 and 1.0
Print Int(Rnd(5,10)) ' any integer from 5 to 9

Attention: When trying to generate integers around 0, don't write Int(Rnd(-10,10))! Because all numbers between -1.0 and +1.0 will get cast to 0, doubling the chance for a 0. Instead, write:

Print (Int(Rnd(21))-10) ' any integer (from 0 to 20)-10 = from -10 to 10
See also

Seed