problem with Random.nextGaussian()

前端 未结 6 2026
别跟我提以往
别跟我提以往 2021-01-12 19:58

Random.nextGaussian() is supposed to give random no.s with mean 0 and std deviation 1. Many no.s it generated are outside range of [-1,+1]. how can i set so that it gives n

6条回答
  •  逝去的感伤
    2021-01-12 20:42

    A normal distribution gives a non-zero (but "becoming extremely small") probability of seeing values outside [-1, +1] whatever variance you give - you're just squishing the curve, effectively.

    You could use a small variance and then just run the results through a map which cropped anything less than -1 to -1, and anything greater than 1 to 1, but it wouldn't (strictly speaking) be a normal distribution any more.

    What do you need this distribution for, out of interest?

提交回复
热议问题