I have no knowledge in php specifically, but in some languages, when using random numbers, you have to "randomize" the random numbers, otherwise the number is generated always in the same way.
It's a random (not intended) thing that came to me, I don't know if it's your case. Good luck! :)
Comment has been collapsed.
<?php
$stack = array();
for($i=0; $i<10; $i++) $stack[rand(0,5)]++;
for($i=0; $i<=5; $i++) echo @$stack[$i].' times '.$i.'<br/>';
?>
Comment has been collapsed.
I have cero PHP experience, but doesn't PHP's switch use breaks on the cases??
Comment has been collapsed.
You forgot the break operator in your switch construction. Try to read this http://www.php.net/manual/en/control-structures.switch.php
Comment has been collapsed.
You're using switch-case wrong.
switch ($roll){
case 0 : $n0++; break;
case 1 : $n1++; break;
case 2 : $n2++; break;
case 3 : $n3++; break;
case 4 : $n4++; break;
case 5 : $n5++; break;
}
should do a trick. :)
Comment has been collapsed.
110 Comments - Last post 58 minutes ago by Hawkingmeister
18,717 Comments - Last post 4 hours ago by fr0zenX
25 Comments - Last post 4 hours ago by spodamayn
6 Comments - Last post 7 hours ago by Formidolosus
23 Comments - Last post 10 hours ago by SirChrisSwan
134 Comments - Last post 11 hours ago by jarzzz
5,787 Comments - Last post 20 hours ago by Gamy7
16 Comments - Last post 48 seconds ago by jiggakills
9 Comments - Last post 9 minutes ago by enigma9q
33 Comments - Last post 13 minutes ago by Taurus9534
7,778 Comments - Last post 22 minutes ago by Dhia
78 Comments - Last post 36 minutes ago by Moony1986
104 Comments - Last post 44 minutes ago by LieEater
288 Comments - Last post 48 minutes ago by CheMan39
So this make sense in my head.. But I'm lost, I know it's going to be something simple..
Hoping someone out there knows what's going on lol..
What I'm trying to do, is get a random number each time from 0 to 5.
Check the result of each random number.
Then get it to tell me how many times that random number came up.
But what is happening is the results I'm getting back are totally wrong.. I'm looping 10 times as expected. But the incrementing seems wrong.. $n5 always comes out at 10, the last time I ran this, the number 5 only came out twice. So how can that be 10?
It's going to be a school boy error I know, But I'm seriously lacking caffeine here.
Here is the code.
Pastebin
Comment has been collapsed.