Average loop length: Difference between revisions

Replaced "strfmt" by "strformat" which is now equivalent but standard. Replaced the deprecated "random(n)" by "rand(n - 1)".
No edit summary
(Replaced "strfmt" by "strformat" which is now equivalent but standard. Replaced the deprecated "random(n)" by "rand(n - 1)".)
Line 1,356:
=={{header|Nim}}==
{{trans|C}}
<lang nim>import random, math, strfmtstrformat
randomize()
Line 1,380:
inc result
bits = bits or x
x = 1 shl randomrand(n - 1)
echo " n\tavg\texp.\tdiff"
Line 1,389:
let theory = expected(n)
let diff = (avg / theory - 1) * 100
printlnfmtecho fmt"{n:2} {avg:8.4f} {theory:8.4f} {diff:6.3f}%", n, avg, theory, diff</lang>
{{out}}
<pre> n avg exp. diff
Anonymous user