相对于数字的概率

I would like to make a roulette for my PHP site, so I need to set the probability of the items. So I created an array with the probability of the different items:

(the higher the number the higher the chance)

$porpList = [
0 => [
    "prop" => 10000,
    "css" => "gray"
],
1 => [
    "prop" => 1000,
    "css" => "green"
],
2 => [
    "prop" => 100,
    "css" => "blue"
],
3 => [
    "prop" => 10,
    "css" => "violet"
],
4 => [
    "prop" => 1,
    "css" => "yellow"
],
5 => [
    "prop" => 0.1,
    "css" => "orange"
]];

Now comes the difficult part: The User with a higher Level should have a greater chance to get better Items and a lower chance to get trash Items, so with level 1 the probability would be:

10000
1000
100
10
1
0.1

And with Level 50 the probability should be something like this:

1
1
10000
1000
100
10

Logically, I could create a table in which all the possibilities for each level are listed, but I would like to solve this with a formula or similar.

Does anyone know a way to do this?

If you want to implement an actual algorithm to determine probability. I'm out.

If you want to heighten the chances of people rolling better stuff, you could use code similar to this;

$rarities = [
    [
        'prop'  => 100000,
        'css'   => 'gray'
    ],
    [
        'prop'  => 10000,
        'css'   => 'green'
    ],
    [
        'prop'  => 1000,
        'css'   => 'blue'
    ],
    [
        'prop'  => 100,
        'css'   => 'violet'
    ],
    [
        'prop'  => 10,
        'css'   => 'yellow'
    ],
    [
        'prop'  => 1,
        'css'   => 'orange'
    ]
];
$level = 50;
$maxProp = (100000/$level);
$won = 'gray';
for ($i=0;$i<20;$i++)
{
    $roll = random_int(0, $maxProp);
    foreach ($rarities as $rarity)
    {
        if ($rarity['prop'] < $roll)
        {
            break;
        }
        $won = $rarity['css'];
    }
    echo '<span style="color: '.$won.'; font-weight: bold; font-familiy: Arial;">'.$roll.'</span><br/>';

The higher the level, the higher chances are something good will 'drop'.

To the question on how you could adapt the probabilities depending on the level, there are certainly many different formulas imaginable. For instance you could add the a fixed fraction of the level to each probability, which would increase each of them equally. But this increase will have significant effect on the smaller probabilities, while the effect on the bigger ones will be negligible.

function getProps($propList, $level) {
    return array_map(function($row) use ($level) {
        $row['prop'] += $level/50; // adapt factor as desired
        return $row;
    }, $propList);
}

$adaptedPropList = getProps($propList, 50);

This would yield the following result:

Array
(
    [0] => Array
        (
            [prop] => 10001
            [css] => gray
        )
    [1] => Array
        (
            [prop] => 1001
            [css] => green
        )
    [2] => Array
        (
            [prop] => 101
            [css] => blue
        )
    [3] => Array
        (
            [prop] => 11
            [css] => violet
        )
    [4] => Array
        (
            [prop] => 2
            [css] => yellow
        )
    [5] => Array
        (
            [prop] => 1.1
            [css] => orange
        )
)

For actually picking the random CSS value according to these probabilities you could use this function:

function pickRandom($propList) {
    $sum = array_reduce($propList, function($sum, $row) {
        return $sum + $row['prop'];
    }, 0);
    $r = lcg_value() * $sum;
    foreach($propList as $row) {
        $r -= $row['prop'];
        if ($r < 0) return $row['css'];
    }
}

$css = pickRandom($adaptedPropList);