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; }
2 odpowiedzi
+ 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
+ 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