Okey, so i got this program from this site itself.....here is the link http://www.cprogramming.com/complete/guessans.html
Okey, so whenever i run this, the number to be guessed is always 46....why isnt it changing??
Printable View
Okey, so i got this program from this site itself.....here is the link http://www.cprogramming.com/complete/guessans.html
Okey, so whenever i run this, the number to be guessed is always 46....why isnt it changing??
the random number will always be the same at the start, if you put the programme through a loop it will change but then you will have to guess a different random number each time, there is a way around it, if you get rand to give you a random number then run a loop around that value going back to rand every time you guess the number correctly for a new value, hope this makes sence, i'm still a noob too :)Quote:
Originally Posted by striker
The FAQ that joni linked to, shows you how to seed the random number generator using srand(). When you seed with the time, you get an unpredictable result, which is what you want.
Actually, if you forget to seed, or if you use the same seed number, you will get a different number each time through the loop, but you'll get the same sequence of numbers every time you run the program. If it's predictable and repeatable, it's not random! :DQuote:
the random number will always be the same at the start, if you put the programme through a loop it will change but then you will have to guess a different random number each time...