Generate random float numbers in range PHP

前端 未结 5 1792
夕颜
夕颜 2020-12-18 09:38

I have a code that initializes a dice object by the following code:

public function initializeDiceSides($totalSides, $fair, $maxProbability = 100) {
   $maxT         


        
5条回答
  •  醉酒成梦
    2020-12-18 10:15

    A simple approach would be to use lcg_value and multiply with the range and add the min value

    function random_float ($min,$max) {
        return ($min + lcg_value()*(abs($max - $min)));
    }
    

提交回复
热议问题