UpdateSeed (RandomNumberGenerator subroutine): Difference between revisions
m (→Syntax terms) |
mNo edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 2: | Line 2: | ||
This method sets a random number object to the number | This method sets a random number object to the number | ||
that would be created by the [[New (RandomNumberGenerator constructor)|New | that would be created by the <var>[[New (RandomNumberGenerator constructor)|New]]</var> <var>Constructor</var> | ||
with the given Seed and Salt specifications. | with the given <var>Seed</var> and <var>Salt</var> parameter specifications. | ||
==Syntax== | ==Syntax== | ||
{{Template:RandomNumberGenerator:UpdateSeed syntax}} | {{Template:RandomNumberGenerator:UpdateSeed syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>randomNumberGenerator</th> | <tr><th>randomNumberGenerator</th> | ||
<td>A <var>RandomNumberGenerator</var> object variable. </td></tr> | <td>A <var>RandomNumberGenerator</var> object variable. </td></tr> | ||
<tr><th><var>Seed</var></th> | <tr><th><var>Seed</var></th> | ||
<td>An optional, name required, argument that lets you specify a "seed" for the random number generator. If you provide no seed, the method generates a new, "random," starting value for the random number generator. | <td>An optional, [[Notation conventions for methods#Named parameters|name required]], string argument that lets you specify a "seed" for the random number generator. If you provide no seed, the method generates a new, "random," starting value for the random number generator.</td></tr> | ||
<tr><th><var>Salt</var></th> | <tr><th><var>Salt</var></th> | ||
<td>An optional, name required, argument that lets you specify a "salt" for the random number generator. A salt is additional data to be used (along with the explicit or default seed) to improve the randomness of the random generator's initial value. | <td>An optional, name required, string argument that lets you specify a "salt" for the random number generator. A salt is additional data to be used (along with the explicit or default seed) to improve the randomness of the random generator's initial value. | ||
</td></tr> | |||
</table> | </table> | ||
==Examples== | ==Examples== | ||
In the following request, calling <var>UpdateSeed</var> enables the production of a second | |||
In the following request, calling | series of three values of <code>%rand</code> that matches the initial series of three | ||
series of three values of %rand that matches the initial series of three | values of <code>%rand</code>: | ||
values of %rand: | |||
<p class="code">begin | <p class="code">begin | ||
%i is float | %i is float | ||
Line 53: | Line 52: | ||
If instead the random number is created with a salt, | If instead the random number is created with a salt, | ||
as in the following fragment, | as in the following fragment, | ||
an | an <var>UpdateSeed</var> call using the salt produces a unique series of | ||
three values (salted numbers are not reproducible): | three values (salted numbers are not reproducible): | ||
<p class="code">... | <p class="code">... |
Latest revision as of 21:35, 6 November 2012
Reset random sequence with new salt and seed (RandomNumberGenerator class)
This method sets a random number object to the number
that would be created by the New Constructor
with the given Seed and Salt parameter specifications.
Syntax
randomNumberGenerator:UpdateSeed[( [Seed= string], [Salt= string])]
Syntax terms
randomNumberGenerator | A RandomNumberGenerator object variable. |
---|---|
Seed | An optional, name required, string argument that lets you specify a "seed" for the random number generator. If you provide no seed, the method generates a new, "random," starting value for the random number generator. |
Salt | An optional, name required, string argument that lets you specify a "salt" for the random number generator. A salt is additional data to be used (along with the explicit or default seed) to improve the randomness of the random generator's initial value. |
Examples
In the following request, calling UpdateSeed enables the production of a second
series of three values of %rand
that matches the initial series of three
values of %rand
:
begin %i is float %rand is object RandomNumberGenerator %rand = new(seed='help') for %i from 1 to 3 printtext {~} = {%rand:value} end for %rand:updateSeed(seed='help') for %i from 1 to 3 printtext {~} = {%rand:value} end for end
The result is:
%rand:value = 816969049 %rand:value = -148817379 %rand:value = 895846046 %rand:value = 816969049 %rand:value = -148817379 %rand:value = 895846046
If instead the random number is created with a salt, as in the following fragment, an UpdateSeed call using the salt produces a unique series of three values (salted numbers are not reproducible):
... %rand = new(salt='iou') for %i from 1 to 3 printtext {~} = {%rand:value} end for %rand:updateSeed(salt='iou') for %i from 1 to 3 printtext {~} = {%rand:value} end for
A sample result is:
%rand:value = 320947512 %rand:value = 535019615 %rand:value = -526589924 %rand:value = 387949238 %rand:value = 413468100 %rand:value = -807607538