Linear congruential generator: Difference between revisions
m
→{{header|Phix}}: bigatom -> mpfr
m (→{{header|REXX}}: added/changed whitespace and comments.) |
m (→{{header|Phix}}: bigatom -> mpfr) |
||
Line 2,101:
=={{header|Phix}}==
{{libheader|
As per the comments, I had to resort to
<lang Phix>atom seed
include builtins/
function BSDrnd()
-- oh dear, native only works on 64-bit,
return ba_seed▼
-- so, resort to gmp, with the added twist than both
-- 1103515245 and #8000_0000 are greater than 1GB and
-- therefore a smidge too big & need some extra help...
mpz z = mpz_init(seed),
h8 = mpz_init("2147483648") -- (ie #8000_0000)
mpz_mul_si(z,z,5)
mpz_mul_si(z,z,1103515245/5) -- (do in two <1GB factors)
mpz_add_si(z,z,12345)
mpz_fdiv_r(z,z,h8)
seed = mpz_get_atom(z)
end function
▲--function BSDrnd() -- (only works on 64-bit, as per ERRE and UCBLogo above on 32-bit)
▲-- seed = remainder(1103515245 * seed + 12345, #8000_0000)
function MSrnd()
seed = and_bits(seed*214013+2531011,#7FFFFFFF)
return floor(seed/power(2,16))
end function
?"BSDrnd"
seed = 0
?"MSrnd"
for i=1 to 10 do
{{out}}
<pre>
|