Distribution of Random Numbers

前端 未结 5 867
孤独总比滥情好
孤独总比滥情好 2021-02-04 17:22

I have two options of code:

Option 1

int myFunc() {
  return new Random().nextInt();
}

Or:

Option 2

5条回答
  •  醉酒成梦
    2021-02-04 17:46

    In my experience, the best balance between good distribution and performance is given by using something like the "Messerne Twister" generator (see in Apache Commons) . For an even fancier solution, see this.

提交回复
热议问题