20 return "RandGaussZiggurat";
25 const double rzm1 = 2147483648.0, rzm2 = 4294967296.;
26 double dn=3.442619855899,tn=dn,vn=9.91256303526217e-3, q;
27 double de=7.697117470131487, te=de, ve=3.949659822581572e-3;
31 q=vn/std::exp(-.5*dn*dn);
32 kn[0]=(
unsigned long)((dn/q)*rzm1);
39 fn[127]=std::exp(-.5*dn*dn);
42 dn=std::sqrt(-2.*std::log(vn/dn+std::exp(-.5*dn*dn)));
43 kn[i+1]=(
unsigned long)((dn/tn)*rzm1);
45 fn[i]=std::exp(-.5*dn*dn);
51 ke[0]=(
unsigned long)((de/q)*rzm2);
58 fe[255]=std::exp(-de);
61 de=-std::log(ve/de+std::exp(-de));
62 ke[i+1]= (
unsigned long)((de/te)*rzm2);
76 const float r = 3.442620f;
78 unsigned long iz=hz&127;
89 return (hz>0)? r+x : -r-
x;
97 if((
unsigned long)abs(hz)<
kn[
iz])
return (hz*wn[iz]);
111 for (
int i=0; i<size; ++i) {
112 vect[i] =
shoot(mean,stdDev);
118 for (
int i=0; i<size; ++i) {
119 vect[i] =
shoot(mean,stdDev);
125 for (
int i=0; i<size; ++i) {
126 vect[i] =
shoot(anEngine,mean,stdDev);
132 for (
int i=0; i<size; ++i) {
133 vect[i] =
shoot(anEngine,mean,stdDev);
139 for (
int i=0; i<size; ++i) {
146 for (
int i=0; i<size; ++i) {
153 for (
int i=0; i<size; ++i) {
154 vect[i] =
fire( mean, stdDev );
160 for (
int i=0; i<size; ++i) {
161 vect[i] =
fire( mean, stdDev );
166 int pr=os.precision(20);
167 os <<
" " <<
name() <<
"\n";
176 if (inName !=
name()) {
177 is.clear(std::ios::badbit | is.rdstate());
178 std::cerr <<
"Mismatch when expecting to read state of a "
179 <<
name() <<
" distribution\n"
180 <<
"Name found was " << inName
181 <<
"\nistream is left in the badbit state\n";
static bool ziggurat_init()
static bool ziggurat_is_init
static float ziggurat_nfix(long hz, HepRandomEngine *anEngine)
HepRandomEngine & engine()
static unsigned long ke[256]
static float ziggurat_UNI(HepRandomEngine *anEngine)
static unsigned long ziggurat_SHR3(HepRandomEngine *anEngine)
std::istream & get(std::istream &is)
shared_ptr< HepRandomEngine > localEngine
std::istream & get(std::istream &is)
void fireArray(const int size, float *vect)
static float ziggurat_RNOR(HepRandomEngine *anEngine)
virtual ~RandGaussZiggurat()
std::ostream & put(std::ostream &os) const
std::ostream & put(std::ostream &os) const
static void shootArray(const int size, float *vect, float mean=0.0, float stdDev=1.0)
static unsigned long kn[128]
virtual double operator()()
HepRandomEngine & engine()