excluding previously randomized integer, and randomize again without it
Posted
by
Rob
on Stack Overflow
See other posts from Stack Overflow
or by Rob
Published on 2010-02-06T23:28:30Z
Indexed on
2011/02/19
23:25 UTC
Read the original article
Hit count: 140
php
<?php
if (isset($_POST['Roll!'])) {
$sides = $_POST['sides'];
$rolled = rand(1,$sides);
echo "$rolled was rolled by the dice, it is now out!";
}
?>
This is the code I currently have. After rolling that number, however, I want it to roll again, but without the previously rolled number, until it has rolled all number except one, which would be the winning number. I have no idea how to go about doing that. Any ideas?
EDIT: I'm sorry, I should have been more clear, thank you all for the help so far, but I also need to echo each number rolled, such as
echo "$rolledArray[0] was rolled, it lost.\n";
echo "$rolledArray[1] was rolled, it lost.\n";
echo "$rolledArray[2] was rolled, it lost.\n";
echo "$rolledArray[3] was rolled, it lost.\n";
echo "$rolledArray[x] was rolled, it lost.\n";
echo "$rolledArray[x] was rolled, it lost.\n";
echo "$rolledArray[50?] was rolled, it lost.";
EDIT AGAIN: Also I only want them to have to click Roll! once, not multiple times until they've rolled all the numbers, meaning no need for session, I think, though I could be wrong, most of you are clearly more experienced than me.
Sorry, I should have mentioned that before as well.
© Stack Overflow or respective owner