### Random number fun.

So I am a bit bored, and I decided to make a nice easy game of "mastermind", a game where you have to guess 4 numbers, in the correct order. After a select amount of guesses, usually 10 attempts, you either guess right and win, or you lose if you go over 10.

The limiting of the number of guessing is the easy part. What I am having trouble with is the actual number. Having a set number was boring and easy to guess.

So my question is simple, how do I take a rand, and keep that one number and use it as the number I need to guess, but at the same time make it so that each time I re-load the game?

Any help will be nice, thank you.
Last edited on
I believe you are looking for: http://www.cplusplus.com/reference/cstdlib/srand/
I did look at that link ahead of time, but they are printing the random number out, as opposed to using it continually.
Then I guess I don't understand your question. I understand this as you are wanting a new random number each time you run this program, is that wrong?
Create a loop. Each iteration `int rndNum = rand();` etc.
Last edited on
this function make random number between min and max value and print it to the output

 ``12345678910`` ``````void random (const int & __min, const int & __max) { unsigned seed = (int)time(NULL); srand(seed); int range = __max - __min + 1; int r = 0; for (int i=0; i < 10; i++) { r = rand() / 100 % range + __min; cout << r << endl; } }``````
Last edited on
Topic archived. No new replies allowed.