Pseudorandom number generator image: Difference between revisions

(Added Ada solution)
Line 410:
}
</syntaxhighlight>
 
=={{header|jq}}==
'''Works with jq and gojq, the C and Go implementations of jq'''
 
It has been claimed that the elementary cellular automaton with "Rule 30" can
be used as a PRNG,
(see e.g. [[Elementary_cellular_automaton/Random_number_generator]]),
so this entry generates a set of (x,y,color) co-ordinates so that this
hypothesis might be visually evaluated e.g. using the gnuplot program.
 
To keep things brief, the jq fileter definitios at
[[Elementary_cellular_automaton#jq]] are used but not repeated here.
<syntaxhighlight lang=jq>
include "elementary-cellular-automaton" {search : "."}; # the defs at [[Elementary_cellular_automaton#jq]]
 
def binary2number:
reduce (.[]|tonumber) as $x ({p:1}; .n += .p * $x | .p *= 2) | .n;
 
# Emit a stream of $n PRNGs in range(0;255)
def prng($n):
# 30 is 11110
("1" + 100 * "0" )
| [automaton(30; 8 * $n) | .[0:1]]
| _nwise(8) | binary2number ;
 
foreach prng(99*99) as $color ({x:0, y:1};
.color = $color
| .x += 1
| if .x == 100 then .x = 1 | .y += 1 else . end )
| "\(.x) \(.y) \(.color)"
</syntaxhighlight>
Invocation:
<pre>
jq -nrf program.jq > prng.txt
gnuplot
plot("prng.txt") with points palette
</pre>
 
=={{header|Julia}}==
2,442

edits