let transition_rule prng = function
| 0. ->
(fun neighbours configuration cell ->
let n = neighbours.(cell) in
let center = configuration.(cell) in
let result = ref (
center
+ (if center >= 4 then -4 else 0)) in
for i=0 to pred (Array.length n) do
if configuration.(n.(i)) >= 4 then incr result
done;
!result)
| grain_probability ->
if not (0. < grain_probability && grain_probability <= 1.) then failwith "grain_probability must lie between 0. and 1.";
(fun neighbours configuration cell ->
let n = neighbours.(cell) in
let center = configuration.(cell) in
let result = ref (
center
+ (if center >= 4 then -4 else 0)
+ int_of_bool (Random.State.float prng 1. < grain_probability)) in
for i=0 to pred (Array.length n) do
if configuration.(n.(i)) >= 4 then incr result
done;
!result)