Elementary cellular automaton/Random number generator: Difference between revisions

Content added Content deleted
m (alphabetize!)
Line 90: Line 90:
{{out}}
{{out}}
<pre>220 197 147 174 117 97 149 171 240 241</pre>
<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}}==
=={{header|D}}==
Line 172: Line 150:
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|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}}==
=={{header|Perl}}==