Jump to content

Elementary cellular automaton/Random number generator: Difference between revisions

m
alphabetize!
m (alphabetize!)
Line 90:
{{out}}
<pre>220 197 147 174 117 97 149 171 240 241</pre>
 
=={{header|J}}==
ca is a cellular automata class. The rng class inherits ca and extends it with bit and byte verbs to sample the ca.
<lang J>
coclass'ca'
DOC =: 'locale creation: (RULE ; INITIAL_STATE) conew ''ca'''
create =: 3 :'''RULE STATE'' =: y'
next =: 3 :'STATE =: RULE (((8$2) #: [) {~ [: #. [: -. [: |: |.~"1 0&_1 0 1@]) STATE'
coclass'base'
 
coclass'rng'
coinsert'ca'
bit =: 3 :'([ next) ({. STATE)'
byte =: [: #. [: , [: bit"0 (i.8)"_
coclass'base'
</lang>
Having installed these into a j session we create and use the mathematica prng.
<pre>
m =: (30 ; 64 {. 1) conew 'rng'
byte__m"0 i.10
220 197 147 174 117 97 149 171 100 151
</pre>
 
=={{header|D}}==
Line 172 ⟶ 150:
44</pre>
Run-time: less than two seconds with the ldc2 compiler.
 
=={{header|J}}==
ca is a cellular automata class. The rng class inherits ca and extends it with bit and byte verbs to sample the ca.
<lang J>
coclass'ca'
DOC =: 'locale creation: (RULE ; INITIAL_STATE) conew ''ca'''
create =: 3 :'''RULE STATE'' =: y'
next =: 3 :'STATE =: RULE (((8$2) #: [) {~ [: #. [: -. [: |: |.~"1 0&_1 0 1@]) STATE'
coclass'base'
 
coclass'rng'
coinsert'ca'
bit =: 3 :'([ next) ({. STATE)'
byte =: [: #. [: , [: bit"0 (i.8)"_
coclass'base'
</lang>
Having installed these into a j session we create and use the mathematica prng.
<pre>
m =: (30 ; 64 {. 1) conew 'rng'
byte__m"0 i.10
220 197 147 174 117 97 149 171 100 151
</pre>
 
=={{header|Perl}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.