I hate the fact that every time i need to get some random numbers in a program i'll have to use the 'C' library srand and rand functions because the so called library random number generators always got me disappointed and so i had to give up on them "they always gave me predictable sequences" something i could do without them but now i want to take the challenge and know why they misbehaved when i needed them , for example the following function always returns the same random sequence on each program execution..
Actually i read from an article that the consistency in the produced sequence during different program execution was meant to be handy during testing and debugging but that make no sense to me if the glorified testing functionality continues to impose limitations in my program's performance
What do i need to do to get real random numbers (i mean unpredictable sequences) similar to those i get with srand?
To get a different sequence of numbers you need to use a different seed. In the program above you use 43323 as the seed. Often the current time (e.g. std::time(0) or std::chrono::high_resolution_clock::now().time_since_epoch().count()) is used as the seed.
you can also use std::random_device from <random>. It generates random numbers and you don't have to seed it. It's pretty slow so use it just as a seed.
Peter87 already told about that, but why are you using std::default_random_engine u_engine(43323); in the first place?
And why are you saying that srand will help here? If you do srand(43323), you will get same results on every execution too.
std::default_random_engine And I would not suggest it either: you do not know what that engine would be. And usually it is LCG, which gives you pretty bad randomness.
I suggest using std::mt19937: a Mersenne Twister algorithm which gives you good tradeoff between randoness and speed.
Before using random_device, insert check if it is really random. On some platform it might give you same sequence each time. http://stackoverflow.com/a/18880689
LCG = Linear Congruental Generator, simpliest PRNG possible.
Because of its generation method, small changes in seed (and time() changes slowly: once each second) will result to small changes in resulting bit pattern on first iterations (then differences will accumulate enough to ensure at least some randomness). And distributions not always use all bits from RNG: they usually uses as much as needed to ensure uniform distribution, and they do not take into account that some bits might be not random or that result of calling RNG might strongly correlate with result of previous execution.