Get a random number focused on center

后端 未结 20 3005
离开以前
离开以前 2020-12-12 09:28

Is it possible to get a random number between 1-100 and keep the results mainly within the 40-60 range? I mean, it will go out of that range rarely, but I want it to be main

20条回答
  •  一生所求
    2020-12-12 09:43

    I needed to solve this problem a few years ago and my solution was easier than any of the other answers.

    I generated 3 randoms between the bounds and averaged them. This pulls the result towards the centre but leaves it completely possible to reach the extremities.

提交回复
热议问题