oILAB
Loading...
Searching...
No Matches
randomInteger.h
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 2/7/24.
3//
4
5#ifndef OILAB_RANDOM_H
6#define OILAB_RANDOM_H
7#include <iostream>
8#include <random>
9
10namespace oILAB {
11template <typename T> T random(const T &a, const T &b) {
12 std::random_device rd; // a seed source for the random number engine
13 std::mt19937 gen(rd()); // mersenne_twister_engine seeded with rd()
14 if (typeid(T) == typeid(int)) {
15 std::uniform_int_distribution<> distrib(a, b);
16 return distrib(gen);
17 } else if (typeid(T) == typeid(double)) {
18 std::uniform_real_distribution<> distrib(a, b);
19 return distrib(gen);
20 } else {
21 throw(std::runtime_error("Unknown type\n"));
22 }
23 }
24 } // namespace oILAB
25#endif //OILAB_RANDOM_H
T random(const T &a, const T &b)