From a3e831fb3e2bf0c0053daafbdafd8ffb651cd3e4 Mon Sep 17 00:00:00 2001 From: GothamK <43772245+GothamK@users.noreply.github.com> Date: Sat, 29 Oct 2022 13:49:05 +0530 Subject: [PATCH] Random number generator in range of (min,max) in linear_congruential_engine --- tests/src/random-gen.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/src/random-gen.cpp diff --git a/tests/src/random-gen.cpp b/tests/src/random-gen.cpp new file mode 100644 index 000000000..4b87a63ac --- /dev/null +++ b/tests/src/random-gen.cpp @@ -0,0 +1,29 @@ + +// Random number generator in range of (min,max) +// in linear_congruential_engine + +#include +#include +#include +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; +}