RandomNumberGenerator class

From m204wiki
Jump to: navigation, search

As its name suggests, the RandomNumberGenerator class is designed to generate random numbers. It is patterned after the Sirius functions $Random and $Random_Seed.

The class differs from the $functions in these important ways:

  • For flexibility, the "seeds" specified to the methods are arbitrary length longstrings, not numbers. The longstrings are MD5 hashed to be used as a seed.
  • "Salt" values are available on some methods to provide additional random data for creating a random seed. Like the seed, the salt is MD5 hashed and then included as part of the initial random data.

The methods in the class include a New constructor to instantiate an object, a Value method for printing as well as constraining the random number value range, and an UpdateSeed method to reset the value of an object.

The RandomNumberGenerator class is new as of Sirius Mods version 7.3.

Example

As an example, the methods in this request create a reproducible sequence of ten numbers between 0 and 99:

b %rand is object randomNumberGenerator %i is float %rand = new(seed='abcd') for %i from 1 to 10 printtext {~} = {%rand:value(0, 99)} end for end

List of RandomNumberGenerator methods

The "List of RandomNumberGenerator methods" contains a complete list of the class methods.