Subtractive generator: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added whitespace.) |
|||
Line 1,019: | Line 1,019: | ||
506003769 |
506003769 |
||
380969305</pre> |
380969305</pre> |
||
=={{header|Julia}}== |
|||
Here is a script, which does not use multiplicative operators, without relying on the optimizer. |
|||
{{works with|Julia|1.0}} |
|||
<lang julia>i,j,m,d,seed = 55,24,10^9,34,292929 # parameters |
|||
s = Array{Int32}(undef,i); r = similar(s) |
|||
s[1:2] = [seed,1] # table initialization |
|||
for n = 3:i; (s[n] = s[n-2]-s[n-1]) < 0 && (s[n] += m) end |
|||
t = 1; for u=1:i; (global t+=d)>i && (t-=i); r[u]=s[t] end # permutation, r = s[(d*(1:i) .% i).+1] |
|||
u,v,n = i,i-j,i-1 |
|||
while (n += 1) > 0 |
|||
(global u += 1) > i && (u = 1) # circular indexing: u,v = ((n,n-j) .% i).+1 |
|||
(global v += 1) > i && (v = 1) |
|||
(r[u] -= r[v]) < 0 && (r[u] += m) # table update |
|||
n < 220 && continue # 165 silent values |
|||
print((n,r[u])) # show (index,value) of next pseudorandom number |
|||
x = readline(stdin) # wait until the ENTER key is pressed |
|||
length(x) > 0 && break # any other key before ENTER => exit |
|||
end</lang> |
|||
{{out}} |
|||
<pre>(220, 467478574) |
|||
(221, 512932792) |
|||
(222, 539453717) |
|||
(223, 20349702) |
|||
(224, 615542081) |
|||
(225, 378707948) |
|||
(226, 933204586) |
|||
(227, 824858649) |
|||
(228, 506003769) |
|||
(229, 380969305) |
|||
(230, 442823364) |
|||
(231, 994162810) |
|||
(232, 261423281)</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |