0
Rand() Function Problem
Can someone helpme solve the Rand() problem. It takes an input called range and is supposed to generate randoms all in a row
7 Answers
+ 3
#include <iostream>
using namespace std;
int main() {
srand(0);
int range;
cin >> range;
//your code goes here
for(int i=1; i<=4; i++) //condition use <=, not >=
{
cout << rand()%range << endl;
}
return 0;
}
//**it produce same output for every run.
+ 1
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
srand(0);
int range;
cin >> range;
//your code goes here
for(int i=1; i>=4; i++)
{
cout << rand() % range;
}
return 0;
}
+ 1
//this is working, there is not required space and range required is 1 to N (inclusive) so add 1
#include <iostream>
using namespace std;
int main() {
srand(0);
int range;
cin >> range;
//your code goes here
for(int i=1; i<=4; i++) //condition use <=, not >=
{
cout << rand()%range+1;
}
return 0;
}
0
This is my current code
0
Thank you, that gets some output now however it is not matching what the test cases are outputting
0
What is the actual question? Add description here...
0
The rand() function
You must set a PIN for your suitcase that contains 4 digits in the range of 0 to N.
Write a program to take the N number as input, generate 4 random numbers from the range and print them sequentially, without spaces.
Sample Input
9
Sample Output
2818
Use rand() function to generate the numbers from required range.
srand(0) is used to match the output, so don't change it.