4 ms·
side question: any recommendations for a good, portable, linear prng in C++ we can embed in some proprietary code? We are doing some simulations which we run o
by gumby 9y ago
side question: any recommendations for a good, portable, linear prng in C++ we can embed in some proprietary code? We are doing some simulations which we run on multiple architectures and sometimes want to re run with different input parameters...and so want the same stream of "random" numbers for multiple runs.
My understanding (perhaps wrong?) is that open openSSL prng is exponential.
- tptacek 9y agoWhat's "good"? If security doesn't matter, for your application, random(3) might do just fine. One simple way to generate a deterministic RNG is to run a hash or a cipher (encrypting an all zeroes block, or a secret) in counter mode. MD5 of some application secret and a counter might suffice for you (it will be plenty fast).
- wolf550e 9y ago"exponential" in what? You can just encrypt a counter using AES or ChaCha ([1]) to produce 2^68 random bytes from 24 initial bytes. You can use HKDF to expand 16 bytes into as many key+nonce pairs as you want, each producing 2^68 random bytes. 1 - use AES if your hardware has AESNI, my mobile i7 can do AES at 5GB/sec on a single core
- gumby 9y agoThanks, this is a good idea. We don't need fast, we need repeatable so that the same seed into the same prng produces the same number on different machines (different CPUs, different OSes) which is why we want to change from simply using the system facilities as we do now. Yet the number of calls to rand() in each simulation is high enough that we don't want to simply keep a large table of random numbers.
- wolf550e 9y agoAES and ChaCha are very repeatable. :-) They also happen to be fast.