RandomNumberGenerator class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
As its name suggests, the RandomNumberGenerator class
As its name suggests, the RandomNumberGenerator class
is designed to generate random numbers.
is designed to generate random numbers.
It is patterned after the Sirius functions $Random and $Random_Seed, described
It is patterned after the Sirius functions [[$Random]] and [[$Random_SEED]].
in the [[Sirius Functions Reference Manual]].
   
   
The class differs from the $functions in these important ways:
The class differs from the $functions in these important ways:
Line 34: Line 33:
end
end
</p>
</p>
==List of RandomNumberGenerator methods==
==List of RandomNumberGenerator methods==
The [[List of RandomNumberGenerator methods|"List of RandomNumberGenerator methods"]] contains a complete list of the class methods.
The [[List of RandomNumberGenerator methods|"List of RandomNumberGenerator methods"]] contains a complete list of the class methods.


[[Category:System classes]]
[[Category:System classes]]

Revision as of 23:48, 23 December 2011

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.