RandomNumberGenerator class: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 6: | Line 6: | ||
The class differs from the $functions in these important ways: | The class differs from the $functions in these important ways: | ||
<ul> | <ul> | ||
<li>For flexibility, the | <li>For flexibility, the "seeds" specified to the methods are arbitrary length | ||
longstrings, not numbers. | longstrings, not numbers. | ||
The longstrings are MD5 hashed to be used as a seed. | The longstrings are MD5 hashed to be used as a seed. | ||
<li> | <li>"Salt" values are available on some methods to provide additional random data for creating a random seed. | ||
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. | ||
Like the seed, the salt | |||
is MD5 hashed and then included as part of the initial random data. | |||
</ul> | </ul> | ||
The methods in the class include a New constructor to instantiate an object, | 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 | 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. | range, and an UpdateSeed method to reset the value of an object. | ||
As an example, | The RandomNumberGenerator class is new as of ''Sirius Mods'' version 7.3. | ||
the methods in this request create a reproducible sequence of ten numbers | |||
==Example== | |||
As an example, the methods in this request create a reproducible sequence of ten numbers | |||
between 0 and 99: | between 0 and 99: | ||
<p class="code">b | |||
%rand is object randomNumberGenerator | |||
%i is float | |||
%rand = new(seed='abcd') | |||
for %i from 1 to 10 | |||
[[Targeted Text statements|printtext]] {~} = {%rand:value(0, 99)} | [[Targeted Text statements|printtext]] {~} = {%rand:value(0, 99)} | ||
end for | |||
end | |||
</p> | |||
The RandomNumberGenerator class | ==List of RandomNumberGenerator 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:45, 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, described in the Sirius Functions Reference Manual.
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.