-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnrandom.h
More file actions
40 lines (32 loc) · 793 Bytes
/
nrandom.h
File metadata and controls
40 lines (32 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* defines namespace nrandom
2016.04.08:
Now that C++11 is a thing (it wasn't when I first wrote this file),
we have standardized (and fast) random number generators built-in.
Today's rewrite eliminates dependencies on dSFMT.h and dSFMT.c.
*/
#pragma once
#include <random>
namespace nrandom {
std::random_device randev;
std::mt19937_64 rangen( randev() );
double exponential (
double mean
) {
static std::exponential_distribution<> expdist;
return expdist( rangen ) * mean;
}
double gaussian (
double mean,
double stddev
) {
static std::normal_distribution<> normdist;
return normdist( rangen ) * stddev + mean;
}
double uniform (
double a,
double b
) {
static std::uniform_real_distribution<> unidist;
return unidist( rangen ) * ( b - a ) + a;
}
}