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

13th Feb 2022, 4:20 PM
Brian
7 Respostas
+ 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.
13th Feb 2022, 5:12 PM
Jayakrishna 🇼🇳
+ 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; }
13th Feb 2022, 4:24 PM
Brian
+ 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; }
14th Feb 2022, 11:39 AM
Jayakrishna 🇼🇳
0
This is my current code
13th Feb 2022, 4:24 PM
Brian
0
Thank you, that gets some output now however it is not matching what the test cases are outputting
13th Feb 2022, 7:54 PM
Brian
0
What is the actual question? Add description here...
13th Feb 2022, 8:41 PM
Jayakrishna 🇼🇳
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.
14th Feb 2022, 11:18 AM
Brian