New (RandomNumberGenerator constructor): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 1: Line 1:
<span style="font-size:120%; color:black"><b>Create a random number object</b></span>
{{Template:RandomNumberGenerator:New subtitle}}
[[Category:RandomNumberGenerator methods|New constructor]]
<!--DPL?? Category:RandomNumberGenerator methods|New constructor: Create a random number object-->
<!--DPL?? Category:System methods|New (RandomNumberGenerator constructor): Create a random number object-->
<p>
New is a member of the [[RandomNumberGenerator class]].
</p>


The New method creates a random number.
The New method creates a random number.
Line 19: Line 13:
recreating or resetting the object with the same seed lets you reproduce the series.
recreating or resetting the object with the same seed lets you reproduce the series.
</ul>
</ul>
===Syntax===
==Syntax==
  %rand = new([Seed=seed] [,&nbsp;Salt=salt])
{{Template:RandomNumberGenerator:New syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
Line 26: Line 20:
<td>A RandomNumberGenerator object variable. </td></tr>
<td>A RandomNumberGenerator object variable. </td></tr>
<tr><th><b>Seed=</b><i>seed</i></th>
<tr><th><b>Seed=</b><i>seed</i></th>
<td>An optional, name required, argument that lets you specify a &ldquo;seed&rdquo; for the random number generator. If you provide no seed, the method generates a new, &ldquo;random,&rdquo; starting value for the random number generator, which produces an unpredictable random number result.
<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, which produces an unpredictable random number result.
  ''seed'' is a string or a longstring. </td></tr>
  ''seed'' is a string or a longstring. </td></tr>
<tr><th><b>Salt=</b><i>salt</i></th>
<tr><th><b>Salt=</b><i>salt</i></th>
<td>An optional, name required, argument that lets you specify a &ldquo;salt&rdquo; 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, 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.
  ''salt'' is a string or a longstring.</td></tr>
  ''salt'' is a string or a longstring.</td></tr>
</table>
</table>


===Usage Notes===
==Usage notes==
<ul>
<ul>
<li>If no Seed argument is specified, the New method generates a random seed
<li>If no Seed argument is specified, the New method generates a random seed
Line 48: Line 42:
<li>For an example of the New method, see the [[RandomNumberGenerator class#Example|RandomNumberGenerator class]] page.
<li>For an example of the New method, see the [[RandomNumberGenerator class#Example|RandomNumberGenerator class]] page.
</ul>
</ul>
==See also==
{{Template:RandomNumberGenerator:New footer}}

Revision as of 19:49, 6 February 2011

Create a new RandomNumberGenerator (RandomNumberGenerator class)


The New method creates a random number. The kind of random number depends on the parameters specified when New is invoked:

  • If no parameters are specified, New returns an unpredictable random number each time it is called.
  • If a Salt parameter is specified, New returns an unpredictable random number that is based on initial input that has an extra degree of randomness.
  • If only a Seed parameter is specified, New returns the next number in a specific series of pseudo-random numbers. Subsequent identical calls produce the next items in the series; recreating or resetting the object with the same seed lets you reproduce the series.

Syntax

%randomNumberGenerator = [%(RandomNumberGenerator):]New[( [Seed= string], - [Salt= string])]

Syntax terms

%rand A RandomNumberGenerator object variable.
Seed=seed 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, which produces an unpredictable random number result. seed is a string or a longstring.
Salt=salt 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. salt is a string or a longstring.

Usage notes

  • If no Seed argument is specified, the New method generates a random seed (based on multiple, internal system data like STCK value, frequently-changed parts of memory, and so on).
  • If you want to increase the randomness of the initial value passed to the random number generator, but you don't want a reproducible sequence, you can pass additional data to be used to generate the random starting value, maybe from something a user types in. This additional value is called a salt.
  • Since the likely use of explicitly specifying a seed is to produce a reproducible random sequence, there is probably not much reason to specify both a salt and a seed, which would nullify reproducibility.
  • For an example of the New method, see the RandomNumberGenerator class page.

See also