Random number generator (device): Difference between revisions
no edit summary
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
No edit summary |
||
Line 737:
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}}==
|