Java中的快速实值随机生成器 [英] Fast real valued random generator in java
问题描述
java.util.Random.nextDouble()对我来说很慢,我需要非常快的东西.
java.util.Random.nextDouble() is slow for me and I need something really fast.
我做了一些谷歌搜索,但我发现只有基于整数的快速随机生成器.区间< 0,1)中的实数在这里有用吗?
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) ?
推荐答案
如果您需要快速的东西并且可以访问Java8,我可以推荐java.utils
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.
如果您需要更快或更更好的算法,我可以推荐以下一种专门的XorShift变体:
If you need a even faster or better algorithm I can recommend one of these specialized XorShift variants:
- Xoroshiro128 + (更快更好) )
- XorShift1024 * (速度类似,甚至更长的时间)
- Xoroshiro128+ (faster & better)
- XorShift1024* (similar speed, even longer period)
有关这些算法及其质量的信息,可以在此PRNG比较中找到.
Information on these algorithms and their quality can be found in this big PRNG comparison.
我进行了独立的性能比较,您可以在此处找到详细的结果和代码: github.com/tobijdc/PRNG性能
I made an independent Performance comparison you can find the detailed results and the code here: github.com/tobijdc/PRNG-Performance
TLDR
请勿使用java.util.Random
,请使用java.util.SplittableRandom
.
如果您需要更快或更优质的PRNG,请使用XorShift变体.
Never use java.util.Random
, use java.util.SplittableRandom
.
If you need faster or better PRNG use a XorShift variant.
这篇关于Java中的快速实值随机生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!