RosettaCodeData/Task/Linear-congruential-generator/Icon/linear-congruential-generator.icon
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

25 lines
649 B
Text

link printf
procedure main()
printf(" BSD MS\n")
every 1 to 10 do
printf("%10s %10s\n",rand_BSD(),rand_MS())
end
procedure srand_BSD(x) #: seed random
static seed
return seed := \x | \seed | 0 # parm or seed or zero if none
end
procedure rand_BSD() #: lcrng
return srand_BSD((1103515245 * srand_BSD() + 12345) % 2147483648)
end
procedure srand_MS(x) #: seed random
static seed
return seed := \x | \seed | 0 # parm or seed or zero if none
end
procedure rand_MS() #: lcrng
return ishift(srand_MS((214013 * srand_MS() + 2531011) % 2147483648),-16)
end