Jump to content

Unbias a random generator: Difference between revisions

Added Easylang
m (→‎{{header|Wren}}: Minor tidy)
(Added Easylang)
Line 573:
5: 19.958% 49.987%
6: 16.660% 49.890%</pre>
 
=={{header|EasyLang}}==
{{trans|Java}}
<syntaxhighlight>
func biased n .
return if randomf < 1 / n
.
func unbiased n .
repeat
a = biased n
b = biased n
until a <> b
.
return a
.
m = 50000
for n = 3 to 6
c1 = 0
c2 = 0
for i to m
c1 += biased n
c2 += unbiased n
.
print n & ": " & 100 * c1 / m & " " & 100 * c2 / m
.
</syntaxhighlight>
{{out}}
<pre>
3: 33.29 50.21
4: 24.70 49.89
5: 20.30 49.45
6: 17 49.78
</pre>
 
=={{header|Elena}}==
2,042

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.