Make Random Numbers Tend / Average to a Specific Value

前端 未结 3 661

How can I for example generate a list of random numbers between 0 and 1, but have them avarage at 0.8?

I have written this little script in C++ that\'ll tell you wh

3条回答
  •  庸人自扰
    2020-12-22 06:36

    NolanPower had a great idea using powers, but the mechanism he recommended for choosing the power is off. If the random numbers U are uniform(0,1) the law of the unconscious statistician says we can derive the expected value of any function g(U) as Integral[g(U) from: 0 to: 1]. If our function g(U) is a polynomial, i.e., U**c for some constant c, evaluating the integral yields the general solution 1 / (c + 1) as the expected value. Setting this equal to the desired mean m and solving, we get that c = (1 / m) - 1.

    To get an expected value of 0.8, c = (1 / 0.8) - 1 = 0.25, i.e., crank out U**0.25. To get an expected value of 0.2, c = (1 / 0.2) - 1 = 4, i.e., generate values using U**4.

提交回复
热议问题