Latin Hypercube Samples (lhs)
1.0
R, C++, and Rcpp code to generate Latin hypercube samples
CRandom.h
Go to the documentation of this file.
1
21
/*** from sunif.c ****/
22
/*
23
* Mathlib : A C Library of Special Functions
24
* Copyright (C) 2000, 2003 The R Core Team
25
*
26
* This program is free software; you can redistribute it and/or modify
27
* it under the terms of the GNU General Public License as published by
28
* the Free Software Foundation; either version 2 of the License, or
29
* (at your option) any later version.
30
*
31
* This program is distributed in the hope that it will be useful,
32
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34
* GNU General Public License for more details.
35
*
36
* You should have received a copy of the GNU General Public License
37
* along with this program; if not, a copy is available at
38
* http://www.r-project.org/Licenses/
39
*
40
*/
41
42
#ifndef CRANDOM_H
43
#define CRANDOM_H
44
45
namespace
bclib
46
{
51
template
<
class
T>
52
class
CRandom
53
{
54
public
:
59
virtual
T
getNextRandom
() = 0;
60
};
61
65
class
CRandomStandardUniform
:
public
CRandom
<double>
66
{
67
public
:
71
CRandomStandardUniform
(){m_i1 = 1234; m_i2 = 5678;};
72
77
double
getNextRandom
()
78
{
79
m_i1 = 36969*(m_i1 & 0177777) + (m_i1>>16);
80
m_i2= 18000*(m_i2 & 0177777) + (m_i2>>16);
81
return
((m_i1 << 16)^(m_i2 & 0177777)) * 2.328306437080797e-10;
/* in [0,1) */
82
};
83
89
void
setSeed
(
unsigned
int
i1,
unsigned
int
i2)
90
{
91
m_i1 = i1; m_i2 = i2;
92
}
93
99
void
getSeed
(
unsigned
int
*i1,
unsigned
int
*i2)
100
{
101
*i1 = m_i1; *i2 = m_i2;
102
}
103
104
private
:
105
unsigned
int
m_i1;
106
unsigned
int
m_i2;
107
};
108
}
109
110
#endif
/* CRANDOM_H */
111
bclib::CRandomStandardUniform::setSeed
void setSeed(unsigned int i1, unsigned int i2)
Definition:
CRandom.h:89
bclib::CRandomStandardUniform::getSeed
void getSeed(unsigned int *i1, unsigned int *i2)
Definition:
CRandom.h:99
bclib::CRandomStandardUniform
Definition:
CRandom.h:66
bclib::CRandomStandardUniform::getNextRandom
double getNextRandom()
Definition:
CRandom.h:77
bclib::CRandom::getNextRandom
virtual T getNextRandom()=0
bclib::CRandom
Definition:
CRandom.h:53
bclib::CRandomStandardUniform::CRandomStandardUniform
CRandomStandardUniform()
Definition:
CRandom.h:71
src
CRandom.h
Generated by
1.8.20