Skip to content

Commit a3e831f

Browse files
authored
Random number generator in range of (min,max) in linear_congruential_engine
1 parent d5c643b commit a3e831f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/src/random-gen.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Random number generator in range of (min,max)
3+
// in linear_congruential_engine
4+
5+
#include <iostream>
6+
#include <chrono>
7+
#include <random>
8+
using namespace std;
9+
10+
// driver program
11+
int main ()
12+
{
13+
14+
// finds the time between the system clock
15+
//(present time) and clock's epoch
16+
unsigned seed = chrono::system_clock::now().time_since_epoch().count();
17+
18+
// minstd_rand0 is a standard
19+
// linear_congruential_engine
20+
minstd_rand0 generator (seed);
21+
22+
// generates the random number
23+
cout << generator() << " is a random number between ";
24+
25+
//use of min and max functions
26+
cout << generator.min() << " and " << generator.max();
27+
28+
return 0;
29+
}

0 commit comments

Comments
 (0)