(phixonline)-->
with javascript_semantics
atom seed
include builtins/mpfr.e
function BSDrnd()
-- oh dear, native only works on 64-bit,
-- as per ERRE and UCBLogo above on 32-bit...
-- seed = remainder(1103515245 * seed + 12345, #8000_0000)
-- 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),
m9 = mpz_init("1103515245"),
h8 = mpz_init("0x80000000")
mpz_mul(z,z,m9)
mpz_add_si(z,z,12345)
mpz_fdiv_r(z,z,h8)
seed = mpz_get_atom(z)
return seed
end function
function MSrnd()
seed = and_bits(seed*214013+2531011,#7FFFFFFF)
return floor(seed/power(2,16))
end function
seed = 0
?"BSDrnd"
for i=1 to 10 do printf(1,"%d\n",BSDrnd()) end for
seed = 0
?"MSrnd"
for i=1 to 10 do printf(1,"%d\n",MSrnd()) end for