Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c + + LAB: Unique random integers ( set ) Given integer inputs howMany and maxNum, generate a vector of howMany unique random integers
in c LAB: Unique random integers set Given integer inputs howMany and maxNum, generate a vector of howMany unique random integers from to maxNum exclusive The structure of the program is: main calls UniqueRandomInts with arguments howMany, and maxNum. UniqueRandomInts returns a vector of howMany unique random integers. The required output is already provided in main and PrintNums Complete UniqueRandomInts which generates random integers until howMany unique integers have been collected in vector nums. Hint: If a generated number is new, add the number to vector nums and set alreadySeen. If the number has been seen before, increment the global variable retries and generate another random integer. Note: For testing purposes, the random number generator is seeded with a fixed value in main Ex: When the input is: the output is retries #include #include #include using namespace std; Print the integers in vector nums separated by a space void PrintNumsvector nums, int size for int i ; i size; i cout nums.ati; Used in uniqueRandomInt, printed in main int retries; Generate howMany unique random integers N maxNum and return in nums vector UniqueRandomIntsunsigned int howMany, int maxNum int nextRand; retries ; set alreadySeen; vector nums; Type your code here. int main unsigned int howMany; unsigned int maxNum; cin howMany; cin maxNum; vector uniqueInts; srand; Seed random number generator for testing uniqueInts UniqueRandomIntshowMany maxNum; PrintNumsuniqueInts howMany; cout retries retries endl; return ;
in c
LAB: Unique random integers set
Given integer inputs howMany and maxNum, generate a vector of howMany unique random integers from to maxNum exclusive
The structure of the program is:
main calls UniqueRandomInts with arguments howMany, and maxNum.
UniqueRandomInts returns a vector of howMany unique random integers.
The required output is already provided in main and PrintNums
Complete UniqueRandomInts which generates random integers until howMany unique integers have been collected in vector nums.
Hint: If a generated number is new, add the number to vector nums and set alreadySeen. If the number has been seen before, increment the global variable retries and generate another random integer.
Note: For testing purposes, the random number generator is seeded with a fixed value in main
Ex: When the input is:
the output is
retries
#include
#include
#include
using namespace std;
Print the integers in vector nums separated by a space
void PrintNumsvector nums, int size
for int i ; i size; i
cout nums.ati;
Used in uniqueRandomInt, printed in main
int retries;
Generate howMany unique random integers N maxNum and return in nums
vector UniqueRandomIntsunsigned int howMany, int maxNum
int nextRand;
retries ;
set alreadySeen;
vector nums;
Type your code here.
int main
unsigned int howMany;
unsigned int maxNum;
cin howMany;
cin maxNum;
vector uniqueInts;
srand; Seed random number generator for testing
uniqueInts UniqueRandomIntshowMany maxNum;
PrintNumsuniqueInts howMany;
cout retries retries endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started