Random number generator in range of (min,max) in linear_congruential_engine
This commit is contained in:
parent
d5c643b13c
commit
a3e831fb3e
29
tests/src/random-gen.cpp
Normal file
29
tests/src/random-gen.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
// Random number generator in range of (min,max)
|
||||
// in linear_congruential_engine
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
using namespace std;
|
||||
|
||||
// driver program
|
||||
int main ()
|
||||
{
|
||||
|
||||
// finds the time between the system clock
|
||||
//(present time) and clock's epoch
|
||||
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
|
||||
|
||||
// minstd_rand0 is a standard
|
||||
// linear_congruential_engine
|
||||
minstd_rand0 generator (seed);
|
||||
|
||||
// generates the random number
|
||||
cout << generator() << " is a random number between ";
|
||||
|
||||
//use of min and max functions
|
||||
cout << generator.min() << " and " << generator.max();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user