You're request isn't very clear. However, suppose you have your own probability distribution for lifes:
lifes | probability | prob. density |
1 - 99 | 50% | 0.00505 |
100 - 199 | 49% | 0.00490 |
200 - 200 | 1% | 0.01005 |
Where third column holds discrete densities of probability
(note I've arbitrarly boosted number 200
density to make cumulative sum be 1
, as required).
Now, if you extract a random number with uniform probability (as
Random
does) you've to equate the cumulative probability functions to get the corrensponding number of your distribution.
Since the granularity of our densities is
10^-5
, we can choose the interval
0-9999
9 for
Random
and use only integer numbers, this way:
Random outcome | choosen life |
0-504 | 1 |
505-1010 | 2 |
... | .. |
49490-49994 | 99 |
49995-50484 | 100 |
50485-50974 | 101 |
... | .. |
98505-98994 | 199 |
98995-99999 | 200 |
Implementing such logic is almost trivial:
public static int myNext(Random r)
{
n = r.Next(100000);
if (n < 49995)
{
return 1 + (n / 505);
}
else if (n < 98995)
{
return 100 + ((n - 49995) / 490);
}
else
{
return 200;
}
}
:)