java 随机生成图,Java中的快速实值随机生成器
java.util.Random.nextDouble() is slow for me and I need something really fast.
I did some google search and I've found only integers based fast random generators. Is here anything for real numbers from interval <0, 1) ?
解決方案
If you need something fast and have access to Java8, I can recommend the java.utils SplitableRandom. It is faster (~twice as fast) and has better statistical distribution.
If you need a even faster or better algorithm I can recommend one of these specialized XorShift variants:
Xoroshiro128+ (faster & better)
XorShift1024* (similar speed, even longer period)
Information on these algorithms and their quality can be found in this big PRNG comparison.
I made an independent Performance comparison you can find the detailed results and the code here: github.com/tobijdc/PRNG-Performance
TLDR
Never use java.util.Random, use java.util.SplittableRandom.
If you need faster or better PRNG use a XorShift variant.
總結(jié)
以上是生活随笔為你收集整理的java 随机生成图,Java中的快速实值随机生成器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 专业文化计算机艺考生,专业课和文化课都优
- 下一篇: git 生成ssh key_ubuntu