thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
DRand48Traits.h
1// -*- C++ -*-
2//
3// DRand48Traits.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef DRand48Traits_H
10#define DRand48Traits_H
11
12#include <cstdlib>
13#include "ACDCTraits.h"
14
15namespace ACDCGenerator {
16
20struct DRAND48 {};
21
26template <>
27struct ACDCRandomTraits<DRAND48>: public ACDCTraitsType {
28
32 static inline double rnd(DRAND48 * r) { return drand48(); }
33
37 static inline double rnd(DRAND48 * r, double xl, double xu) {
38 return xl + (xu - xl)*rnd(r);
39 }
40
52 template <typename InputIterator, typename OutputIterator>
53 static inline void rnd(DRAND48 * r, InputIterator l, InputIterator lend,
54 InputIterator u, OutputIterator res) {
55 for ( ; l != lend; ++l ) *res++ = *l + (*u++ - *l)*rnd(r);
56 }
57
62 template <typename OutputIterator>
63 static inline void rnd(DRAND48 * r, int D, OutputIterator res) {
64 for ( int d = 0; d < D; ++d ) *res++ = rnd(r);
65 }
66
70 static inline bool rndBool(DRAND48 * r, double x) { return rnd(r) < x; }
71
75 static inline bool rndBool(DRAND48 * r, double x, double y) {
76 return rndBool(r, x/(x + y)); }
77
81 static inline long rndInt(DRAND48 * r, long x) {
82 return long(rnd(r, 0.0, double(x))); }
83
84};
85
88}
89
90#endif
The namespace in which all ACDCGen classes are defined.
Definition: ACDCGen.h:18
static long rndInt(Rnd *r, long x)
Return a random integer in the interval [0,x[.
Definition: ACDCTraits.h:101
static double rnd(Rnd *r)
Return a flat random number in the interval ]0,1[.
Definition: ACDCTraits.h:52
static bool rndBool(Rnd *r, double x)
Return true with probability x.
Definition: ACDCTraits.h:90