15 lines
489 B
Text
15 lines
489 B
Text
constant iterations = 1_000_000,
|
|
fmt = """
|
|
Wakings over %,d repetitions = %,d
|
|
Percentage probability of heads on waking = %f%%
|
|
"""
|
|
integer heads = 0, wakings = 0
|
|
for i=1 to iterations do
|
|
integer flip = rand(2) -- 1==heads, 2==tails
|
|
wakings += 1 + (flip==2)
|
|
heads += (flip==1)
|
|
end for
|
|
-- or (same output, <1% of the time):
|
|
--integer heads = sum(sq_eq(sq_rand(repeat(2,iterations)),1)),
|
|
-- wakings = 2*iterations-heads
|
|
printf(1,fmt,{iterations,wakings,heads/wakings*100})
|