June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,40 @@
// version 1.1.51
const val MOD = 1_000_000_000
val state = IntArray(55)
var si = 0
var sj = 0
fun subrandSeed(p: Int) {
var p1 = p
var p2 = 1
state[0] = p1 % MOD
var j = 21
for (i in 1..54) {
if (j >=55) j -= 55
state[j] = p2
p2 = p1 - p2
if (p2 < 0) p2 += MOD
p1 = state[j]
j += 21
}
si = 0
sj = 24
repeat(165) { subrand() }
}
fun subrand(): Int {
if (si == sj) subrandSeed(0)
if (si-- == 0) si = 54
if (sj-- == 0) sj = 54
var x = state[si] - state[sj]
if (x < 0) x += MOD
state[si] = x
return x
}
fun main(args: Array<String>) {
subrandSeed(292_929)
for (i in 0..9) println("r[${i + 220}] = ${subrand()}")
}

View file

@ -1,4 +1,4 @@
sub bentley_clever($seed) {
sub bentley-clever($seed) {
constant $mod = 1_000_000_000;
my @seeds = ($seed % $mod, 1, (* - *) % $mod ... *)[^55];
my @state = @seeds[ 34, (* + 34 ) % 55 ... 0 ];
@ -13,5 +13,5 @@ sub bentley_clever($seed) {
&subrand ... *;
}
my @sr := bentley_clever(292929);
my @sr = bentley-clever(292929);
.say for @sr[^10];

View file

@ -1,6 +1,6 @@
/*REXX program uses a subtractive generator, and creates a sequence of random numbers. */
s.0=292929; s.1=1; billion=10**9 /* ◄────────┐ */
numeric digits 20; billion=1e9 /*same as─►─┘ */
s.0=292929; s.1=1; billion=1e9 /* ◄────────┐ */
numeric digits 20; billion=10**9 /*same as─►─┘ */
cI=55; do i=2 to cI-1
s.i=mod(s(i-2) - s(i-1), billion)
end /*i*/