Elementary cellular automaton/Random number generator: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Minor tidy) |
(Added FreeBASIC) |
||
Line 181: | Line 181: | ||
44</pre> |
44</pre> |
||
Run-time: less than two seconds with the ldc2 compiler. |
Run-time: less than two seconds with the ldc2 compiler. |
||
=={{header|FreeBASIC}}== |
|||
{{trans|Go}} |
|||
<syntaxhighlight lang="vbnet">Const n As Uinteger = 64 |
|||
#define pow2(x) Culng(1) Shl x |
|||
Sub Evolve(state As Integer, rule As Integer) |
|||
Dim As Integer i, p, q |
|||
Dim As Ulongint b, st, t1, t2, t3 |
|||
For p = 0 To 9 |
|||
b = 0 |
|||
For q = 7 To 0 Step -1 |
|||
st = state |
|||
b Or= (st And 1) Shl q |
|||
state = 0 |
|||
For i = 0 To n - 1 |
|||
t1 = Iif(i > 0, st Shr (i - 1), st Shr 63) |
|||
Select Case i |
|||
Case 0: t2 = st Shl 1 |
|||
Case 1: t2 = st Shl 63 |
|||
Case Else: t2 = st Shl (n + 1 - i) |
|||
End Select |
|||
t3 = 7 And (t1 Or t2) |
|||
If (rule And pow2(t3)) <> 0 Then state Or= pow2(i) |
|||
Next i |
|||
Next q |
|||
Print Using "####"; b; |
|||
Next p |
|||
Print |
|||
End Sub |
|||
Evolve(1, 30) |
|||
Sleep</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 220 197 147 174 117 97 149 171 100 151</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |