As the title suggests, I am trying to figure out a way of generating random numbers using the new C++11 library. I have tried it with this code:<
You've got two common situations. The first is that you want random numbers and aren't too fussed about the quality or execution speed. In that case, use the following macro
#define uniform() (rand()/(RAND_MAX + 1.0))
that gives you p in the range 0 to 1 - epsilon (unless RAND_MAX is bigger than the precision of a double, but worry about that when you come to it).
int x = (int) (uniform() * N);
Now gives a random integer on 0 to N -1.
If you need other distributions, you have to transform p. Or sometimes it's easier to call uniform() several times.
If you want repeatable behaviour, seed with a constant, otherwise seed with a call to time().
Now if you are bothered about quality or run time performance, rewrite uniform(). But otherwise don't touch the code. Always keep uniform() on 0 to 1 minus epsilon. Now you can wrap the C++ random number library to create a better uniform(), but that's a sort of medium-level option. If you are bothered about the characteristics of the RNG, then it's also worth investing a bit of time to understand how the underlying methods work, then provide one. So you've got complete control of the code, and you can guarantee that with the same seed, the sequence will always be exactly the same, regardless of platform or which version of C++ you are linking to.