Dice game probabilities: Difference between revisions

no edit summary
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
No edit summary
Line 687:
sys 0m0,003s
</pre>
 
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn RollTheDice( dice as long, sides as long ) as long
long i, total = 0
for i = 1 to dice
total += rnd(sides)
next
end fn = total
 
 
void local fn CaclulateProbabilities( dice1 as long, sides1 as long, dice2 as long, sides2 as long )
long i, player1, player2
float total1 = 0, total2 = 0, total3 = 0
for i = 1 to 100000
player1 = fn RollTheDice( dice1, sides1 )
player2 = fn RollTheDice( dice2, sides2 )
if ( player1 > player2 ) then total1++ : continue
if ( player1 < player2 ) then total2++ : continue
if ( player1 == player2 ) then total3++ : continue
next
printf @"Dice cast %ld times.", i - 1
printf @"Player 1 with %ld dice of %ld sides.", dice1, sides1
printf @"Player 2 with %ld dice of %ld sides.", dice2, sides2
printf @"Total wins Player 1 = %.f. Probability of winning: %0.4f%%.", total1, (total1 / i ) * 100
printf @"Total wins Player 2 = %.f", total2
printf @"Number of ties: %.f.", total3
end fn
 
randomize
print
fn CaclulateProbabilities( 9, 4, 6, 6 )
print
fn CaclulateProbabilities( 5, 10, 6, 7 )
print
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Dice cast 100000 times.
Player 1 with 9 dice of 4 sides.
Player 2 with 6 dice of 6 sides.
Total wins Player 1 = 57301. Probability of winning: 57.3004%.
Total wins Player 2 = 35733
Number of ties: 6966.
 
Dice cast 100000 times.
Player 1 with 5 dice of 10 sides.
Player 2 with 6 dice of 7 sides.
Total wins Player 1 = 64289. Probability of winning: 64.2884%.
Total wins Player 2 = 31296
Number of ties: 4415.
</pre>
 
 
 
=={{header|Gambas}}==
715

edits