how do i random?
In the world of online and roleplay games a quite common phenomena , random chances to win an item. From 100% to ridiculous 0,01% or even lower everything is being represented and while the bigger numbers tend to be ignored , people get obsessed with smaller numbers. With that there come theory’s of randomness and of course false concepts such as the following:
"the item has 1% so i have to attempt to obtain it 100 times to finally get it"
That however is not correct since every new attempt has the same random chance as the previous. With a quite low chance for example 1% the player may see the item appear after the first attempt or maybe after the 200th attempt or never see the item at all , no matter how many attempts. Too many attempts are frustrating , to keep players happy you need to guarantee them the item. But how can item appearance be kept rare and yet guaranteed? By increasing the chance with every continuous attempt.
The following example provides 2 methods , the first is the common known random every single attempt. The second however increases the chance after every failed attempt. The output shows the number of attempts required for each method and compares them to each other. This whole step will be repeated 10 times or more to get a more genuine overview.
// --- seed srand((double) microtime() * 1000000); // --- how often do we want to test? for ($attempt = 0; $attempt < 10; $attempt++) { // --- chance to win $chance = 1; // -------------- // --- method 1: // ------------- // --- reset the counter $counter = $chance+1; // --- roll untill lower then our result while ($chance < $counter) { // --- get a random number $counter = mt_rand(1,100); // --- increase the amount of attempts for this method $result[$attempt][1]++; } // ------------- // --- method 2: // ------------ // --- reset the counter $counter = $chance+1; // --- reset inner counter for this method $ctr = 0; // --- roll untill lower then our result while($chance < $counter) { // --- get random number , decrease range with each roll $counter = mt_rand(1,100-$ctr); // --- counter to decrease range $ctr++; // --- increase the amount of attempts for this method $result[$attempt][2]++; } } // --- print out results foreach($result AS $att) { // --- number of rolls for method 1 echo $att[1]; // --- method 1 needed more rolls then method 2 if ($att[1] > $att[2]) { echo " > "; $x++; } // --- method 2 needed more rolls then method 1 else if ($att[1] < $att[2]) { echo " < "; $y++; } // --- both method requires equal amount else { echo " = "; } // --- number of rolls for method 2 echo $att[2]."
"; } // --- final count results echo "
1: ".$y."
"; echo "2: ".$x."
"; echo "-: ".($attempt-$x-$y)."
"; ?>
The above output shows that the first method can require a quite huge amount way above the expected false logic (1% equals max 100 attempts) where as the second method is always within the expected false logic range.
But why bother with all this randomness or not , what does it matter if the item appears after 100 or 100000 attempts? The player does decide if your game is successful and percentages will always become public on fansites or user filled databases. Low numbers can turn the player away but that’s a rare occasion , whats more frustrating though is if the low number comes on top of a streak of bad luck rolls.