Earlier quoted context omitted.
Probably looking for this: https://en.m.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
This seems to use an external random number generator. I want the code to be complete and reproducible. So gimmeTheNumberAtPosition(x) will always return the same for the same x. Also, FYShuffle is much more complex than I would like the algo to be.
Evolution of Random Number Generators
31–40 of 56 posts
Re: Evolution of Random Number Generators
#32Recently noted that mt19937, mt19937_64 are much faster than the standard c++ random generator. They are also possibly better with regards to number distribution, but the performance difference is gigantic on clang. The standard 32 bit std::default_random_generator is almost 40x slower than the 64 bit mt19937_64 one across the board, from -o1 to -O3 march... etc. As all of them are also faster than old school rand, i…
MT is pretty slow. There are fast variants (SFMT), but why use that when can have much better and much faster rngs? https://rurban.github.io/dieharder/QUALITY.html
If RNG speed matters and you need a lot of random numbers in succession (and I assume these two assumptions correlate strongly) editing MT to directly pull 4 or even 8 random numbers at once (i.e. a `__m256 rand_m256()` interface) is a huge performance gain.
wyrand (the top spot of the linked benchmark), doesn't have this benefit. The computation can't be SIMDified and the extraction is always a single value.
So I would take these benchmark with a grain of salt and take a closer look at the specific situation for any application where RNG speed really matters.
Re: Evolution of Random Number Generators
#33Recently noted that mt19937, mt19937_64 are much faster than the standard c++ random generator. They are also possibly better with regards to number distribution, but the performance difference is gigantic on clang. The standard 32 bit std::default_random_generator is almost 40x slower than the 64 bit mt19937_64 one across the board, from -o1 to -O3 march... etc. As all of them are also faster than old school rand, i…
MT is pretty slow. There are fast variants (SFMT), but why use that when can have much better and much faster rngs? https://rurban.github.io/dieharder/QUALITY.html
Re: Evolution of Random Number Generators
#34Earlier quoted context omitted.
MT is pretty slow. There are fast variants (SFMT), but why use that when can have much better and much faster rngs? https://rurban.github.io/dieharder/QUALITY.html
I don't know about all the other RNGs in this benchmark, but MT prepares a dense/contiguous array of random numbers. The whole computation can be SIMDified (often even by the compiler), but extraction is (unless changed explicitly) a single copy of a double. If RNG speed matters and you need a lot of random numbers in succession (and I assume these two assumptions correlate strongly) editing MT to directly pull 4 or…
Re: Evolution of Random Number Generators
#35Earlier quoted context omitted.
I don't know about all the other RNGs in this benchmark, but MT prepares a dense/contiguous array of random numbers. The whole computation can be SIMDified (often even by the compiler), but extraction is (unless changed explicitly) a single copy of a double. If RNG speed matters and you need a lot of random numbers in succession (and I assume these two assumptions correlate strongly) editing MT to directly pull 4 or…
Wouldn't a SIMDified implementation of other RNGs speed them up by a comparable factor, making MT relatively slower again?
You could simdify computation with different seeds tho, which might be fine for many purposes. However at that point it's also a custom implementation with a different number sequence than the non-simd version, which isn't the case with a SIMDified MT.
Re: Evolution of Random Number Generators
#36Earlier quoted context omitted.
Probably looking for this: https://en.m.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
This seems to use an external random number generator. I want the code to be complete and reproducible. So gimmeTheNumberAtPosition(x) will always return the same for the same x. Also, FYShuffle is much more complex than I would like the algo to be.
Isn't the Lehmer code the thing that you want? Then you can specify your permutation with an integer and extract the individual digits from it repeatedly.
Re: Evolution of Random Number Generators
#37Earlier quoted context omitted.
Wouldn't a SIMDified implementation of other RNGs speed them up by a comparable factor, making MT relatively slower again?
If the next number depends on the previous number (like with wyrand and many others) it can't be simdified. You could simdify computation with different seeds tho, which might be fine for many purposes. However at that point it's also a custom implementation with a different number sequence than the non-simd version, which isn't the case with a SIMDified MT.
Re: Evolution of Random Number Generators
#38I am looking for a simple random number generator that fills a given amount of slots. Say it is initialized with "size=5" then it might output: 3,5,2,1,4 Is there something like this? It does not need much statistical resemblence to randomness. Just look kind of random to the eye. And the code should be short. A few lines of Javascript or so. Maybe one approach might be to just loop through the sequence (1,2,3,4,5) a…
int start = getRandomInt(seed) % N;
double k = N / 1.618;
k = k % 2 == 0 ? k - 1 : k; // k and N must be coprime
int nextElement = k * start % N;
start++;
This will jump wildly across your sequence and visit all elements (as k and N are chosen coprime). No need to store a full array. Is it statistically random? Of course not, e.g. you will never see two values close to each other right after another.Re: Evolution of Random Number Generators
#39Recently noted that mt19937, mt19937_64 are much faster than the standard c++ random generator. They are also possibly better with regards to number distribution, but the performance difference is gigantic on clang. The standard 32 bit std::default_random_generator is almost 40x slower than the 64 bit mt19937_64 one across the board, from -o1 to -O3 march... etc. As all of them are also faster than old school rand, i…
I think both the PCG family and the xoroshiro family are faster still. https://prng.di.unimi.it https://www.pcg-random.org ETA: https://github.com/lemire/testingRNG
Re: Evolution of Random Number Generators
#40I am looking for a simple random number generator that fills a given amount of slots. Say it is initialized with "size=5" then it might output: 3,5,2,1,4 Is there something like this? It does not need much statistical resemblence to randomness. Just look kind of random to the eye. And the code should be short. A few lines of Javascript or so. Maybe one approach might be to just loop through the sequence (1,2,3,4,5) a…
[1]: http://pcgworkshop.com/archive/mawhorter2019anarchy.pdf [2]: https://github.com/solsword/anarchy