Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ranlux support? #62

Closed
supertrianguloid opened this issue Feb 23, 2025 · 5 comments
Closed

Add Ranlux support? #62

supertrianguloid opened this issue Feb 23, 2025 · 5 comments

Comments

@supertrianguloid
Copy link

Ranlux is the industry-standard RNG for large-scale Monte Carlo simulations. I searched but did not find any discussion about its omission or potential inclusion.

Has there been any discussion about potentially adding this (that I just didn't find)?
Would anyone be interested in a PR for this? (It sounds like a fun weekend project)

@dhardy
Copy link
Member

dhardy commented Feb 23, 2025

Yes, you did: rust-random/rand#1549

As hinted at there, I believe the only value of the algorithm is historical — in case one wishes to reproduce old results. This would of course be hard to do with a different random library — many of the sampling algorithms in rand/rand_distr will not perform identically to whatever other library you'd be comparing to and thus would not produce identical results even with an identical PRNG.

Otherwise, you might as well just use one of our current RNGs, e.g. ChaCha8Rng.

@vks
Copy link
Contributor

vks commented Feb 23, 2025

I don't think it's the industry standard anymore.

If I recall correctly, it's about 10 times slower than the Mersenne Twister, which seems more popular nowadays. However, even the Mersenne Twister is slower and of less statistical quality than the state of the art (e.g the xoshiro or ChaCha RNGs).

Unless you want to reproduce old results obtained with ranlux, I cannot think of a reason to use it over the alternatives we already have in Rand.

@supertrianguloid
Copy link
Author

It is for sure still the industry standard in my field! (Lattice QFT). Everyone still uses it. As far as I understand, it's much better than mersenne twister statistically. I've not seen a comparison of the statistical quality of Ranlux with e.g. PCG. I looked through the PCG paper and it's compared for speed, but in our field the quality of the RNG is much more important than the speed of the RNG (it's never the bottleneck). I wonder if there is some comparison somewhere you could point me to? If there are statistically better RNGs I'm happy to switch! :)

@dhardy
Copy link
Member

dhardy commented Feb 23, 2025

CSPRNGs have higher quality requirements than MC simulations. Read this: https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Requirements

To the best of my knowledge, ChaCha12 passes these security requirements (read rust-random/rand#932). ChaCha8 may also; it will certainly also suffice where security is not required.

Small PRNGs like PCG and Xoshiro score well on statistical tests aside from a few issues: state may be too small to support many streams / jumps, Xoshiro can perform poorly around zero (and some other values), and bit-avalanche of seeds can be low, hence it is important not to use seeds with a low Hamming weight or multiple seeds which are similar (we provide SeedableRng::seed_from_u64 to work around this). Also read through rust-random/rand#910.

For your application I'd recommend ChaCha8.

@supertrianguloid
Copy link
Author

Thanks for the information!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants