normal.h | normal.h | |||
---|---|---|---|---|
// -*- C++ -*- | ||||
// $Id$ | ||||
/* | /* | |||
* This is a modification of the Kinderman + Monahan algorithm for | * This is a modification of the Kinderman + Monahan algorithm for | |||
* generating normal random numbers, due to Leva: | * generating normal random numbers, due to Leva: | |||
* | * | |||
* J.L. Leva, Algorithm 712. A normal random number generator, ACM Trans. | * J.L. Leva, Algorithm 712. A normal random number generator, ACM Trans. | |||
* Math. Softw. 18 (1992) 454--455. | * Math. Softw. 18 (1992) 454--455. | |||
* | * | |||
* http://www.acm.org/pubs/citations/journals/toms/1992-18-4/p449-leva/ | * http://www.acm.org/pubs/citations/journals/toms/1992-18-4/p449-leva/ | |||
* | * | |||
* Note: Some of the constants used below look like they have dubious | * Note: Some of the constants used below look like they have dubious | |||
skipping to change at line 37 | skipping to change at line 40 | |||
BZ_NAMESPACE(ranlib) | BZ_NAMESPACE(ranlib) | |||
template<typename T = double, typename IRNG = defaultIRNG, | template<typename T = double, typename IRNG = defaultIRNG, | |||
typename stateTag = defaultState> | typename stateTag = defaultState> | |||
class NormalUnit : public UniformOpen<T,IRNG,stateTag> | class NormalUnit : public UniformOpen<T,IRNG,stateTag> | |||
{ | { | |||
public: | public: | |||
typedef T T_numtype; | typedef T T_numtype; | |||
NormalUnit() {} | ||||
explicit NormalUnit(unsigned int i) : | ||||
UniformOpen<T,IRNG,stateTag>(i) {}; | ||||
T random() | T random() | |||
{ | { | |||
const T s = 0.449871, t = -0.386595, a = 0.19600, b = 0.25472; | const T s = 0.449871, t = -0.386595, a = 0.19600, b = 0.25472; | |||
const T r1 = 0.27597, r2 = 0.27846; | const T r1 = 0.27597, r2 = 0.27846; | |||
T u, v; | T u, v; | |||
for (;;) { | for (;;) { | |||
// Generate P = (u,v) uniform in rectangle enclosing | // Generate P = (u,v) uniform in rectangle enclosing | |||
// acceptance region: | // acceptance region: | |||
skipping to change at line 91 | skipping to change at line 99 | |||
public: | public: | |||
typedef T T_numtype; | typedef T T_numtype; | |||
Normal(T mean, T standardDeviation) | Normal(T mean, T standardDeviation) | |||
{ | { | |||
mean_ = mean; | mean_ = mean; | |||
standardDeviation_ = standardDeviation; | standardDeviation_ = standardDeviation; | |||
} | } | |||
Normal(T mean, T standardDeviation, unsigned int i) : | ||||
NormalUnit<T,IRNG,stateTag>(i) | ||||
{ | ||||
mean_ = mean; | ||||
standardDeviation_ = standardDeviation; | ||||
}; | ||||
T random() | T random() | |||
{ | { | |||
return mean_ + standardDeviation_ | return mean_ + standardDeviation_ | |||
* NormalUnit<T,IRNG,stateTag>::random(); | * NormalUnit<T,IRNG,stateTag>::random(); | |||
} | } | |||
private: | private: | |||
T mean_; | T mean_; | |||
T standardDeviation_; | T standardDeviation_; | |||
}; | }; | |||
End of changes. 3 change blocks. | ||||
0 lines changed or deleted | 15 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |