in reply to Simulating Drawing From A Bag

with the search "shuffling an array" you could have found this: How do I shuffle an array randomly?

Nevertheless, regarding your code, I think there is a problem:

$x = $x > 0 ? $x - 1 : $x;
This will make the chance for a 0 double the chance of any other number.

I wouldn't use splice. I'd go te way of really shuffling the array and then printing it either complete or using the elements in sequence one by one.

For shuffling seethe link I gave above.

Replies are listed 'Best First'.
Re: Re: Simulating Drawing From A Bag
by YAFZ (Pilgrim) on Jun 12, 2003 at 10:52 UTC
    Thanks for drawing my attention to the problem of probability. Since I plan to use this script for some kind of lottery it would be bad for some numbers having more probability compared to others ;-)