RandomNumberGenerator class: Difference between revisions
mNo edit summary |
mNo edit summary |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
As its name suggests, the RandomNumberGenerator class | As its name suggests, the <var>RandomNumberGenerator</var> class is designed to generate random numbers. | ||
is designed to generate random numbers. | It is patterned after the Sirius functions <var>[[$Random]]</var> and <var>[[$Random_Seed]]</var>. | ||
It is patterned after the Sirius functions [[$Random]] and [[$ | |||
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 "seeds" specified to the methods are arbitrary length | <li>For flexibility, the "seeds" specified to the methods are arbitrary length [[Longstrings|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>"Salt" values are available on some methods to provide additional random data for creating a random seed. | <li>"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. | 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 <var>[[New (RandomNumberGenerator constructor)|New]]</var> constructor to instantiate an object, | ||
a Value method for printing as well as constraining the random number value | a <var>[[Value (RandomNumberGenerator function)|Value]]</var> 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 <var>[[UpdateSeed (RandomNumberGenerator subroutine)|UpdateSeed]]</var> method to reset the value of an object. | ||
The RandomNumberGenerator class is new as of | The <var>RandomNumberGenerator</var> class is new as of <var class="product">Sirius Mods</var> version 7.3. | ||
==Example== | ==Example== | ||
As an example, the methods in this request create a reproducible sequence of ten numbers | 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 | <p class="code">b | ||
Latest revision as of 21:53, 13 November 2012
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.