Probabilistic choice: Difference between revisions

Added Quackery.
m (→‎{{header|REXX}}: added a note to the REXX section header about head and foot titles.)
(Added Quackery.)
Line 2,505:
Target probability: 0.200000,0.166667,0.142857,0.125000,0.111111,0.100000,0.090909,0.063456
Attained probability: 0.199720,0.166424,0.142474,0.124561,0.111511,0.100313,0.091316,0.063681</pre>
 
=={{header|Quackery}}==
 
Uses point$ from the bignum rational arithmetic module bigrat.qky. <code>10 point$</code> returns a ratio as a decimal string accurate to 10 decimal places with round-to-nearest on the final digit.
 
<lang Quackery> [ $ "bigrat.qky" loadfile ] now!
 
( --------------- zen object orientation -------------- )
 
[ immovable
]this[ swap do ]done[ ] is object ( [ --> )
 
[ ]'[ ] is method ( --> [ )
 
[ method [ unbuild ] ] is who$ ( --> )
 
[ method
[ dup share
swap put ] ] is localise ( --> )
 
[ method [ release ] ] is delocalise ( --> )
 
 
( ------------------ rand-gen methods ----------------- )
 
[ method
[ dup take
2 split drop
' [ 0 0 ] join
swap put ] ] is reset-gen ( --> [ )
 
[ method
[ dup take
dup 2 peek 1+
swap 2 poke
dup 1 peek random
over 0 peek <
if
[ dup 3 peek 1+
swap 3 poke ]
swap put ] ] is rand-gen ( --> [ )
 
[ method
[ dup echo say ": "
share
dup 2 peek dup echo
say " trials" cr
say " Actual: "
over 3 peek
swap 10 point$ echo$ cr
say " Expected: "
dup 0 peek
swap 1 peek
10 point$ echo$ cr
cr ] ] is report ( --> [ )
 
 
( ------------------ rand-gen objects ----------------- )
 
[ object [ 1 5 0 0 ] ] is aleph ( [ --> )
[ object [ 1 6 0 0 ] ] is beth ( [ --> )
[ object [ 1 7 0 0 ] ] is gimel ( [ --> )
[ object [ 1 8 0 0 ] ] is daleth ( [ --> )
[ object [ 1 9 0 0 ] ] is he ( [ --> )
[ object [ 1 10 0 0 ] ] is waw ( [ --> )
[ object [ 1 11 0 0 ] ] is zayin ( [ --> )
[ object [ 1759 27720 0 0 ] ] is heth ( [ --> )
 
 
' [ aleph beth gimel daleth he waw zayin heth ]
 
dup witheach [ reset-gen swap do ]
 
dup witheach
[ 1000000 times
[ rand-gen over do ]
drop ]
 
witheach [ report swap do ]</lang>
 
{{out}}
 
<pre>aleph: 1000000 trials
Actual: 0.199454
Expected: 0.2
 
beth: 1000000 trials
Actual: 0.166854
Expected: 0.1666666667
 
gimel: 1000000 trials
Actual: 0.142329
Expected: 0.1428571429
 
daleth: 1000000 trials
Actual: 0.12457
Expected: 0.125
 
he: 1000000 trials
Actual: 0.111143
Expected: 0.1111111111
 
waw: 1000000 trials
Actual: 0.100061
Expected: 0.1
 
zayin: 1000000 trials
Actual: 0.090979
Expected: 0.0909090909
 
heth: 1000000 trials
Actual: 0.063131
Expected: 0.0634559885</pre>
 
 
 
=={{header|R}}==
1,462

edits