Re: Random Generators using percentages

From: Date: Fri, 01 Dec 2000 01:41:19 +0000
Subject: Re: Random Generators using percentages
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28149@lists.php.net to get a copy of this message
Person 1 - 250... 25% chance of getting #1, 21.55% chance of getting #2, and 17.84% chance of getting #3 Person 2 - 200... 20% chance of getting #1, 18.91% chance of getting #2, and 17.22% chance of getting #3 Person 3 - 157... 15.70% chance of getting #1, 15.84% chance of getting #2, and 15.70% chance of getting #3 Person 4 - 120... 12% chance of getting #1, 12.71% chance of getting #2, and 13.43% chance of getting #3 Person 5 - 89... 8.90% chance of getting #1, 9.77% chance of getting #2, and 10.82% chance of getting #3 Person 6 - 64... 6.40% chance of getting #1, 7.21% chance of getting #2, and 8.26% chance of getting #3 Person 7 - 44... 4.40% chance of getting #1, 5.06% chance of getting #2, and 5.93% chance of getting #3 Person 8 - 29... 2.90% chance of getting #1, 3.38% chance of getting #2, and 4.03% chance of getting #3 Person 9 - 18... 1.80% chance of getting #1, 2.12% chance of getting #2, and 2.56% chance of getting #3 Person 10 - 9... 0.90% chance of getting #1, 1.07% chance of getting #2, and 1.30% chance of getting #3 Person 11 - 9... 0.90% chance of getting #1, 1.07% chance of getting #2, and 1.30% chance of getting #3 Person 12 - 6... 0.60% chance of getting #1, 0.71% chance of getting #2, and 0.87% chance of getting #3 Person 13 - 5... 0.50% chance of getting #1, 0.60% chance of getting #2, and 0.73% chance of getting #3 You get a random number from 1 to 1000, and then do like this: if ($rand < 250) $result = $person[1] elseif ($rand < 450) $result = $person[2] elseif ($rand < 607) $result = $person[3] . . .

« previous php.general (#28149) next »