Random number generator (device): Difference between revisions

Add ed example
m (syntax highlighting fixup automation)
(Add ed example)
 
(6 intermediate revisions by 6 users not shown)
Line 507:
 
</syntaxhighlight>
 
JPD 2021/07/07
 
Line 673 ⟶ 674:
(random-seed (current-time-milliseconds ))
(random (expt 2 32)) → 1322611152
</syntaxhighlight>
 
=={{header|Ed}}==
<syntaxhighlight>
H
!echo $RANDOM > /tmp/random.ed.txt
r /tmp/random.ed.txt
,p
Q
</syntaxhighlight>
 
Line 737 ⟶ 747:
 
Sleep</syntaxhighlight>
 
 
=={{header|FutureBasic}}==
FB offers a variety of ways to generate random numbers of varying degrees of distribution and randomness accuracy. In addition to its native rnd() function which returns random integers from 1 and higher, it can also access any C library function, i.e, rand(), arc4random, arc4random_uniform, as well as random number generators in Apple's GameplayKit library. Here are a few examples:
<syntaxhighlight lang="freebasic">
include "Tlbx GameplayKit.incl"
 
local fn RandomBigInteger( digits as UInt64 ) as UInt64
end fn = fn GKLinearCongruentialRandomSourceSeed( fn GKLinearCongruentialRandomSourceInit ) mod digits
 
local fn RandomIntegerInRange( min as UInt64, max as UInt64 ) as UInt64
UInt64 rndIntInRange = fn RandomBigInt( max - min + 1 ) + min - 1
end fn = rndIntInRange
 
local fn ArcRandomIntegerInRage( min as long, max as long ) as long
long i
cln i = (arc4random()%(max-min+1))+min;
end fn = fn floor(i)
 
// Returns double in range of 0.0 to 50.0
double r
cln r = (((double)arc4random()/0x100000000)*50);
 
randomInteger = rnd(expr%)
</syntaxhighlight>
 
 
=={{header|GlovePIE}}==
Line 854 ⟶ 890:
}
}</syntaxhighlight>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">DEFINE sysrand32 ==
"/dev/urandom" "r" fopen dup 4 fread swap fclose unswons [swap 256 * +] fold.</syntaxhighlight>
 
=={{header|jq}}==
Line 1,385 ⟶ 1,425:
next
</syntaxhighlight>
 
=={{header|RPL}}==
RAND 2 32 ^ * FLOOR
 
=={{header|Ruby}}==
Line 1,427 ⟶ 1,470:
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func urandom() {
conststatic device = %f'/dev/urandom';
 
device.open('<:raw', \var fh, \var err) ->
|| die "Can't open `#{device}': #{err}";
 
fh.sysread(\var noise, 4);
'L'.unpack(noise);
}
 
say urandom(); # sample: 35174325641989353410</syntaxhighlight>
 
=={{header|Standard ML}}==
Line 1,483 ⟶ 1,526:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
File.open("/dev/urandom") { |file|
76

edits