If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Rand() function

I'm trying to make a simple console game using Microsoft visual c++ 2010. It is a guessing game in which it creates a random number and you try to guess the number. There are two options, 1 to 10, or 1 to 100. The problem is it keeps generating a new random number every time i guess. I need the number to stay the same throughout the game. Does anyone know what the problem is?

Re: Rand() function

Hi,

Please use code tags when posting code (see FAQ's for details)!

srand is menat to be called once (at the start of your program). It initializes the pseudo random generator.

rand itself can be called as often as you want. In case it should be called exactly when you need a new random number. Then you can hold this value in a variable and make your guesses until you'll have got it.