Elementary cellular automaton/Random number generator: Difference between revisions

Added Wren
(Added Wren)
Line 849:
220,197,147,174,241,126,135,130,143,234
Note that as the number of state bits is increased (the parameter to the constructor), the sequence tends to a limit of <math>220,</math> <math>197,</math> <math>147,</math> <math>174,</math> <math>117,</math> <math>97,</math> <math>149,</math> <math>171,</math> <math>240,</math> <math>241,</math> <math>\ldots</math> and that deviations from this are due to interactions between the state modification “wavefront” as the automaton wraps round.
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-big}}
As Wren cannot deal accurately with 64-bit unsigned integers and bit-wise operations thereon, we need to use BigInt here.
<lang ecmascript>import "/big" for BigInt
 
var n = 64
 
var pow2 = Fn.new { |x| BigInt.one << x }
 
var evolve = Fn.new { |state, rule|
for (p in 0..9) {
var b = BigInt.zero
for (q in 7..0) {
var st = state.copy()
b = b | ((st & 1) << q)
state = BigInt.zero
for (i in 0...n) {
var t1 = (i > 0) ? st >> (i-1) : st >> 63
var t2 = (i == 0) ? st << 1 : (i == 1) ? st << 63 : st << (n+1-i)
var t3 = (t1 | t2) & 7
if ((pow2.call(t3) & rule) != BigInt.zero) state = state | pow2.call(i)
}
}
System.write(" %(b)")
}
System.print()
}
 
evolve.call(BigInt.one, 30)</lang>
 
{{out}}
<pre>
220 197 147 174 117 97 149 171 100 151
</pre>
 
=={{header|zkl}}==
9,476

edits