I agree. The reason for this is, that a computer can not just generate a random number. It does not have emotions to pick a number, it must solve it mathematically. There is no equation not actually giving the same each time.
So you have to seed the rand function with the current time. Then in theory tho, rand would return the same if the time is the same each time you run it. Although that shouldn't be the case, since I believe the time function returns the time since 1970 or something.
I already knew that about the "randomness". But random means
an event not able to be predicted by a human. Although I tried this
but when I rerun the program works fine but when I loop on it it doesn't :S
The random number generator has a specific starting value and follows a mathematical formula to generate the next number. If you know the starting value and the formula, you can predict the series that it will generate. That's just the way computerized random number generators are, some are better than others.
What you need to remember is that you have to "seed" the random number generator with a random value to set the starting point. The most reliable way to do this is using srand((unsigned)time(0)); at the beginning of your code. The value of time() is one of the few things in computing that has enough variation in it to simulate true randomness.
Post the section of your code that generates and displays your random numbers. We should be able to tell you what's going on then...
Move the srand() to the very beginning of your program, you only need to do it once for each time the program runs, not for each iteration of your "loop", or every time you use rand().
I suspect that as fast as modern computing equipment runs you are repeatedly re-seeding the random number generator to the same starting value each time. This would have the effect of causing the generator to produce the same 3 numbers repeatedly. The value of time only changes (I believe) once every second (but it may be every millisecond). You can use rand() thousands, if not millions, of times before it needs to be re-seeded.
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...