Random number generator (device): Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: need 'use experimental', laziness works again)
m (→‎version 1: changed some comments.)
Line 617: Line 617:
=={{header|REXX}}==
=={{header|REXX}}==
===version 1===
===version 1===
The   32-bit   random number is unsigned and constructed from two smaller 16-bit   numbers,   and it's expressed in decimal.
<lang rexx>/*REXX program generates a random 32-bit number using the RANDOM bif.*/
/*───────── The 32-bit random number is unsigned and constructed from */
/*───────── two smaller 16-bit numbers, and it's expressed in decimal.*/
/*───────── Note: the REXX random bif has a maximum range of 100,000.*/


Note: &nbsp; the REXX &nbsp; '''random''' &nbsp; BIF has a maximum range
numeric digits 10 /*ensure REXX has enough room. */
of &nbsp; 100,000.
_=2**16 /*a handy-dandy constant to have.*/
<lang rexx>/*REXX program generates and displays a random 32-bit number using the RANDOM BIF.*/

numeric digits 10 /*ensure REXX has enough decimal digits*/
say random(0,_-1)*_+random(0,_-1) /*gen an unsigned 32-bit random #*/</lang>
_=2**16 /*a handy─dandy constant to have around*/
r#= random(0, _-1) * _ + random(0, _-1) /*generate an unsigned 32-bit random #.*/
say r# /*stick a fork in it, we're all done. */</lang>
{{out}}
{{out}}
<pre>
<pre>
4294967296
4294967296
</pre>
</pre>

===version 2===
===version 2===
This program generates a random 4 byte character string in the range '00000000'x to 'ffffffff'x
This program generates a random 4 byte character string in the range '00000000'x to 'ffffffff'x