+ 1

srand on linux

im trying to use srand in my program to generate a number then promt you to guess the number. i Have srand AND rand in my code. but i keep getting the number 84 can anyone help?????????????????????

2nd Jan 2017, 4:49 AM
Michael Darnell
Michael Darnell - avatar
2 odpowiedzi
+ 6
Did you use time(0) to randomise the seed? srand(time(0)); cout << rand() % 100; // outputs random number from 0 to 99
2nd Jan 2017, 6:30 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
thanks for the reply i had int number; srand(etc here); but i moved srand on top of my int and it fixed everything for me. thanks for the reply. i made a little guessing game on my codes. had to go back and fix it xD
9th Jan 2017, 4:07 AM
Michael Darnell
Michael Darnell - avatar