That's because you're reseeding the random number generator by using the srand(time(0)) in the do loop. Move it outside the loop, then cout two or more random numbers. You should find they are different each time.
@whitenight1 you did a slight error line 21 ( x != 50); should be ( x = 50); to keep the loop going, also can you explain what you did with the code, because now its a little better, still very predictable but better
you did a slight error line 21 ( x != 50); should be ( x = 50); to keep the loop going
Doing that would make the loop run forever. If that's what you wanted, you'd just have a while(1) at the top and be done with it.
If your implementation gives 123123123123123123123123123 then it's really, really bad.
The rand that typically comes with the compiler is bad. Really, really bad. If you want decent random numbers use the C++11 random number functions, or a decent random number generator from Boost or some other library.
I took your code, added a few small additions for readability, and compiled with Dev-C++. As you can see, it will print out 360 random numbers which should give you an idea of its randomness. Of course, there will always be the chance for repetition, especially with only having 3 random numbers to choose from.
sorry read your code and becausse of the speed i thought it was 123123123, when in reality it was more random (put a pause at the end), anyways, can you explain why your way comes up with better random numbers (line by line)
Yes the only difference between those two pieces of code is that 't' holds the current time. Since you don't care about the time, you don't need 't'. There is zero difference as far as srand/rand goes.