0

What's wrong?

Lesson 40.2. Why when is coming the second number the result isn't changed. #include <iostream> #include <cstdlib> using namespace std; int main() { srand(0); int range; cin >> range; // for (range=0; range<4;range++){ cout<<1+(rand()%4); } return 0; }

3rd Jul 2021, 11:20 AM
Vladimir Kushner
Vladimir Kushner - avatar
2 Respostas
+ 1
because rand makes random numbers between 0 to a maximum and srand makes that number compeletly random and if you call rand without passing a diffrent number to srand you will give same numbers which are random between 0 to maximum but are same
3rd Jul 2021, 11:33 AM
GHOST mHBr
GHOST mHBr - avatar
+ 1
the maximum number located at RAND_MAX and if you want to have real diffrent numbers you should pass the time value to the srand
3rd Jul 2021, 11:36 AM
GHOST mHBr
GHOST mHBr - avatar