Your problem is related to how you sow the random number generator. Obviously, sowing over time (NULL) will produce the same PRNG sequence for this second when sowing. This is the most common rand seed method, but unfortunately this is bad practice due to this very problem. Not only that, I read that this can lead to biased results.
Note that EVERY PRNG will produce the same result if you see the same values . So your problem is not with the generator, more for sowing.
I asked a question about sowing here just a few weeks ago and got a link to the next article, which you can also find useful. Good practice in (pseudo) random number generation for bioinformatics applications . See Section on sowing or warming up a generator.
rand () is not the best random number generator, but is suitable in many cases if it is correctly sown. If you need something better where the repetition sequence is very long, then there are some in this link. Or use TR1. Personally, I would go with more portable C ++ 03 code and avoid TR1.
Also consider Carry Multiply as an alternative PRNG algorithm.
source share