-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRSrandom.h
More file actions
97 lines (77 loc) · 2.5 KB
/
RSrandom.h
File metadata and controls
97 lines (77 loc) · 2.5 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*----------------------------------------------------------------------------
*
* Copyright (C) 2026 Greta Bocedi, Stephen C.F. Palmer, Justin M.J. Travis, Anne-Kathleen Malchow, Roslyn Henry, Théo Pannetier, Jette Wolff, Damaris Zurell
*
* This file is part of RangeShifter.
*
* RangeShifter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RangeShifter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RangeShifter. If not, see <https://www.gnu.org/licenses/>.
*
--------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
RangeShifter v2.0 RSrandom
Implements the RSrandom class
Authors: Steve Palmer, University of Aberdeen
Anne-Kathleen Malchow, Potsdam University
Last updated: 12 January 2021 by Steve Palmer
------------------------------------------------------------------------------*/
#ifndef RSrandomH
#define RSrandomH
#include <stdlib.h>
#include <fstream>
#include <cassert>
#include <cmath>
#include <random>
#include <set>
#include "Utils.h"
#if !LINUX_CLUSTER
#include <ctime>
#endif
using namespace std;
#if RS_RCPP
typedef uint32_t seed_t;
#else
typedef int seed_t;
#endif
class RSrandom
{
public:
#if !RS_RCPP
RSrandom(void);
#else
RSrandom(std::int64_t); // if int is negative, a random seed will be generated, else it is used as seed
#endif
~RSrandom(void);
double Random(void);
int IRandom(int, int);
float FRandom(float, float);
int Bernoulli(double);
int Binomial(const int& n, const double& p);
double Normal(double, double);
double Gamma(double, double);
double NegExp(double);
int Poisson(double);
mt19937 getRNG(void);
void fixNewSeed(int);
seed_t getSeed() const { return RS_random_seed; };
private:
seed_t RS_random_seed;
std::vector<mt19937> gens;
std::uniform_real_distribution<>* pRandom01;
std::normal_distribution<>* pNormal;
};
#ifdef UNIT_TESTS
void testRSrandom();
#endif // UNIT_TESTS
//---------------------------------------------------------------------------
#endif // RSrandomH