0
Can be talk me about Rand and srand in c++. Pls help.
5 Respuestas
+ 1
In C++ as in most languages, rand is a formula to generate numbers attempting to make them random. The nice thing about it is that by default it always returns the same numbers so you can know what numbers are next and debug your code. Having truly random numbers means that a bug might only happen once a day and you never know when.
srand is how you change where rand starts in the pattern. You pass a number in and the pattern generates the next number from there. To make a random starting number, we normally use the current time. If your program is fast and you manage it run it twice in a single second, both runs will be the same.
+ 1
I don't understand this question. Do you have a program it is related to or a link to some place? If so, please post the link so I can put your question into context.
+ 1
Since there wasn't a srand call made, you can run the program for the rest of your life and it always returns the same number.
0
but , why let 41 ??