+ 1

Why do we use srand()?

https://code.sololearn.com/c9NJ4GbiWsWj/?ref=app #include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { //define the range int from = 8; int to = 42; srand(time(0)); cout << from + (rand() % (to - from + 1)); return 0; } Here SoloLearn used srand function but later using rand function, then why I needed to call srand function?? And why we need to subtract a variable from another??

19th Aug 2021, 9:04 AM
Samael Morningstar
3 ответов
+ 1
Jazz Thanks Jazz!!
19th Aug 2021, 9:30 AM
Samael Morningstar