// Pick a random number for the current player. If the current// player picks '1', add 1 to their total. Otherwise draw again// for the next player, subtracting 1 from the number of picks to// draw from.

for (i = 0;i<iterations;i++){if (random(1,7)==1) {player1++;}else if (random(1,6)==1) {player2++;}else if (random(1,5)==1) {player3++;}else if (random(1,4)==1) {player4++;}else if (random(1,3)==1) {player5++;}else player6++;}// If the draw is a multiple of 1,000 - print the current results to the Serial monitor.

I think you are right about if-else statements, they not doing what supposed to.> (random(1,3)==1) {player5++;} Chances for player5 is much higher than for player1.You should rewrite a code giving equals chances for player to withdraw a number, excluding already taken out numbers

You are running random separately for each player which probably isn't the right way to do it.

And you have to initialize the player counts to zero

int player1 = 0, player2 = 0 , .....

You'd probably be better off using an array for the player counts.

Pete

I was assuming the variables auto initialized to 0. If you don't initialize the variable, what value will it have? Random? I will try initializing to 0 later. I cant see how drawing a new random number each time is a problem although it might not be the most elegant way. I saw it as the easiest way to reduce the number of possibilities for each successive player.

I think you are right about if-else statements, they not doing what supposed to.> (random(1,3)==1) {player5++;} Chances for player5 is much higher than for player1.You should rewrite a code giving equals chances for player to withdraw a number, excluding already taken out numbers

Chances for player 5 should be much higher, since player 5 will only get to draw on those times that players 1-4 do not draw '1'. If players 1-4 draw 1 then that line of code shouldn't even be executed, right?

I saw it as the easiest way to reduce the number of possibilities for each successive player.

If that's what you want to do, that's OK - perhaps you are simulating Russian Roulette in which case your code is correct. But if what you are doing is randomly choosing one of the players each time, then you could do something like this:

Unless the value of chance can change (can a player defer to a different player?) I'd suggest using a switch statement rather than a long list of if statements. But even better would be to stick all the players into an array and have the same code deal with all of them.

I only provide help via the forum - please do not contact me for private consultancy.

Yes, it is something like Russian roulette I guess, without the blowing your head off part. As each successive person draws and misses the next person has a better chance of winning.

I can appreciate the array ideas, but it runs plenty fast enough as is. I was surprised how quickly the Arduino blows throughout 32000 runs of the code. I think my memories of running BASIC on the Apple II and Commodore 64 led me to expect bad performance on the 8 bit Atmel. I didn't account for the compiled code vs interpreted code and the faster clock speed on the Atmel chip.