In: Computer Science
Write a program that repeatedly generates a random integer in the range [1, 100], one integer at a time, and displays the generated numbers on the screen according to the following rules:
1
5
32
68
89
45
31
IN C++ ONLY PLEASE
1- Required program in C++ -->
#include <iostream>
#include <random>
using namespace std;
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(1, 100); // range
1-100
int a=distr(gen); //produce a random variable and store the value
in a
std::cout<<a<<endl; // print a
int c=1; // let c=1
while(c==1){ // while loop will run till break statement is
executed
int b=distr(gen); // produce a random variable and store the value
in b
if(b<=a){ // if b is less than or equal to a
break; // break the while loop
}
std::cout<<b<<endl; // print b
a=b; // assign value of b to a
}
}
2-
Required code in C++ -->
#include <iostream>
#include <random>
using namespace std;
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(1, 100); //
range 1-100
int a=distr(gen); //produce a random variable and store the value
in a
std::cout<<a<<endl; // print a
int c=1; // let c=1
while(c==1){ // while loop will execute till break is used
int b=distr(gen); //produce a random variable and store the value
in b
if(b>=a){ // if b is greater than or equal to
a
break; // break the while loop
}
std::cout<<b<<endl; // print b
a=b; // assign value of b to a
}
}