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
10
namespace
gbLAB
{
11
template
<
typename
T>
12
T
random
(
const
T& a,
const
T& b) {
13
std::random_device rd;
// a seed source for the random number engine
14
std::mt19937 gen(rd());
// mersenne_twister_engine seeded with rd()
15
if
(
typeid
(T) ==
typeid
(
int
)) {
16
std::uniform_int_distribution<> distrib(a, b);
17
return
distrib(gen);
18
}
19
else
if
(
typeid
(T) ==
typeid
(
double
)) {
20
std::uniform_real_distribution<> distrib(a, b);
21
return
distrib(gen);
22
}
23
else
{
24
throw
(std::runtime_error(
"Unknown type\n"
));
25
}
26
}
27
}
28
#endif
//OILAB_RANDOM_H
gbLAB
Definition
BiCrystal.cpp:13
gbLAB::random
T random(const T &a, const T &b)
Definition
randomInteger.h:12
include
Utilities
randomInteger.h
Generated on Wed Aug 6 2025 23:06:44 for oILAB by
1.9.8