#include<iostream>#include<cstdlib>//required for rand(), srand()#include<ctime>//required for time()usingnamespace std;intmain(){srand(time(0));//randomizing results... (using time as an input)constint totalNumbersGenerated =30;constint minRange =1, maxRange =20;
cout<<"
Printing "<<totalNumbersGenerated<<" random integer numbers(from "<<minRange<<" to "<<maxRange<<"):
";for(int i=1;i<=totalNumbersGenerated;i++){//generating random number in specified range (inclusive)
cout<<1+((rand()% maxRange)+ minRange -1)<<" ";}
cout<<endl;return0;}
#include<cstdlib>#include<iostream>#include<ctime>intmain(){
std::srand(std::time(nullptr));// use current time as seed for random generatorint random_variable = std::rand();
std::cout <<"Random value on [0 "<< RAND_MAX <<"]: "<< random_variable << '
';}
// Add thus to with the headers
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());// Generate a function that will give values between l and r inclusiveauto dist =uniform_int_distribution<int>(l, r);// get the random number using dist(rng);
#include<random>typedef std::mt19937 MyRNG;// the Mersenne Twister with a popular choice of parametersuint32_t seed_val;// populate somehow
MyRNG rng;// e.g. keep one global instance (per thread)voidinitialize(){
rng.seed(seed_val);}intmain(){
std::uniform_int_distribution<uint32_t> uint_dist;// by default range [0, MAX]
std::uniform_int_distribution<uint32_t>uint_dist10(0,10);// range [0,10]
std::normal_distribution<double>normal_dist(mean, stddeviation);// N(mean, stddeviation)while(true){
std::cout <<uint_dist(rng)<<" "<<uint_dist10(rng)<<" "<<normal_dist(rng)<< std::endl;}}
#include<iostream>usingnamespace std;intmain(){int sz;
cout<<"Enter the size of array::";
cin>>sz;int randArray[sz];for(int i=0;i<sz;i++)
randArray[i]=rand()%100;//Generate number between 0 to 99
cout<<"
Elements of the array::"<<endl;for(int i=0;i<sz;i++)
cout<<"Elements no "<<i+1<<"::"<<randArray[i]<<endl;return0;}
#include<stdlib.h>#include<ctime>usingnamespace std;//Generate random numbersintmain(){srand(time(0));for(int i =0; i <10; i++){
cout<<(rand()%10)+1<<" ";