Categoryc++

c++ arc4random on android, windows and linux

Turns out native android development doesn’t supply you with a real ar4random method. However adapting the OpenBSD’s arc4random.c does the trick. And even works on windows without using CryptoAPI (thanks to Chris K. Jester-Young for these suggestions). Additionally with boost *ducks* it should be more or less multithreadsafe.

Mixed (red dots are generated by arc4; Math.Random() Arc4random)

And here are the convinience methods for it:

So you can use it like:

Enjoy. (:

See also

Merging and splitting two ints in c++

In c++ an int consists of 4 bytes and can hold a max value of 2147483647 (2^31-1). Should you ever feel the obscure need to merge two ints, because you know that both of your values will never be blow 0 or above 32767 (2^15-1) use the following methods.

1) Merging

2) Splitting

3) applying in a test method

Conclusion:

c++ empoweres me to do probably unnecessary and weird stuff.