Value (RandomNumberGenerator function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 4: Line 4:
of the random number method object.
of the random number method object.
Using this method is the only way to get the random number
Using this method is the only way to get the random number
referred to by a RandomNumberGenerator object variable.
referred to by a <var>RandomNumberGenerator</var> object variable.
==Syntax==
==Syntax==
{{Template:RandomNumberGenerator:Value syntax}}
{{Template:RandomNumberGenerator:Value syntax}}
Line 12: Line 12:
<td>A numeric variable to contain a random integer greater than or equal to ''min'' and less than or equal to ''max''. </td></tr>
<td>A numeric variable to contain a random integer greater than or equal to ''min'' and less than or equal to ''max''. </td></tr>
<tr><th>%rand</th>
<tr><th>%rand</th>
<td>A RandomNumberGenerator object variable. </td></tr>
<td>A <var>RandomNumberGenerator</var> object variable. </td></tr>
<tr><th>min</th>
<tr><th>min</th>
<td>An optional integer that is the lower limit for the generated random number. The minimum value of this argument is the same as its default: -1,000,000,000. </td></tr>
<td>An optional integer that is the lower limit for the generated random number. The minimum value of this argument is the same as its default: -1,000,000,000. </td></tr>
Line 20: Line 20:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>Since the Value method has no parameters,
<li>Since the <var>Value</var> method has no parameters,
you can use either of the following ways if you want a fresh
you can use either of the following ways if you want a fresh
starting datum for each Value call:
starting datum for each <var>Value</var> call:
<p class="code">%num = %(randomNumberGenerator):new:value(1,10)
<p class="code">%num = %(randomNumberGenerator):new:value(1,10)



Revision as of 21:50, 6 February 2011

Get a new random value (RandomNumberGenerator class)


This method returns the integer value, within a default or explicit range, of the random number method object. Using this method is the only way to get the random number referred to by a RandomNumberGenerator object variable.

Syntax

%number = randomNumberGenerator:Value[( [min], [max])]

Syntax terms

%num A numeric variable to contain a random integer greater than or equal to min and less than or equal to max.
%rand A RandomNumberGenerator object variable.
min An optional integer that is the lower limit for the generated random number. The minimum value of this argument is the same as its default: -1,000,000,000.
max An optional integer that is the upper limit for the generated random number. The maximum value of this argument is the same as its default: 1,000,000,000.

Usage notes

  • Since the Value method has no parameters, you can use either of the following ways if you want a fresh starting datum for each Value call:

    %num = %(randomNumberGenerator):new:value(1,10) %num = %(randomNumberGenerator):new(salt=%i):value(1,10)

    In the latter case, %i might be a counter that gets incremented at each New call.

See also