thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
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 
15 namespace ACDCGenerator {
16 
20 struct DRAND48 {};
21 
26 template <>
27 struct 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