What is the best seeded random number generator on ObjC?
I have to generate the same random number sequences on 2 different iPhones, therefore it has to be seeded. This is why I can’t use arc4rand().
NOTE: by best I mean fastest/most unpredictable relation.
The Mersenne Twister implementation that comes with the C++ standard library is very good. As it’s C++, you’ll need to create a wrapper so that you can call it from C and ObjC code, or alternatively rename the file that uses it to have a .mm (Objective-C++) extension.
I’m thinking of something like this, in the header:
And then, in a .cpp file that includes the above:
I haven’t tested the above, but it should be pretty close. You can then include the header in your C/ObjC files as usual, create a rng with a seed, get a bunch of random numbers, and destroy the rng when you’re done. You can also add more generator functions if needed – the library comes with different random distributions you can use.