Probabilistic choice: Difference between revisions
Major rewrite to simplify code
No edit summary |
(Major rewrite to simplify code) |
||
Line 1,445:
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn
double prob(_elements), cumulative(_elements)
Str15 item(_elements)
item(1) = "aleph" : item(2) = "beth" : item(3) = "gimel" : item(4) = "daleth"
▲ long trial, i, n = 1000000
item(5) = "he" : item(6) = "waw" : item(7) = "zayin" : item(8) = "heth"
▲ double p, r, sum = 0, cnt(_arrItems), sumActual = 0
prob(5) = 1/9.0 : prob(6) = 1/10.0 : prob(7) = 1/11.0 : prob(8) = 1759/27720
sum += prob(i)
next
if abs(
for
cln r = (((double)arc4random()/0x100000000));
p =
for
p +=
if (
next
next
print
printf @"
printf @"---- ------ -----------"
▲ for i = 0 To 7
for i
printf @"%-7s %10.6f %12.6f", item(i), cumulative(i)/samples, prob(i)
checksum += cumulative(i)/samples
next
printf @"
printf @"%
end fn
fn ProbabilisticChoice
NSLog( @"%@", fn WindowPrintViewString( 1 ) )
HandleEvents
Line 1,496 ⟶ 1,492:
{{output}}
<pre>
aleph
beth
gimel
he
waw
zayin
heth
</pre>
=={{header|Go}}==
|