srand on linux | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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