00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef DRand48Traits_H
00010 #define DRand48Traits_H
00011
00012 #include <cstdlib>
00013 #include "ACDCTraits.h"
00014
00015 namespace ACDCGenerator {
00016
00020 struct DRAND48 {};
00021
00026 template <>
00027 struct ACDCRandomTraits<DRAND48>: public ACDCTraitsType {
00028
00032 static inline double rnd(DRAND48 * r) { return drand48(); }
00033
00037 static inline double rnd(DRAND48 * r, double xl, double xu) {
00038 return xl + (xu - xl)*rnd(r);
00039 }
00040
00052 template <typename InputIterator, typename OutputIterator>
00053 static inline void rnd(DRAND48 * r, InputIterator l, InputIterator lend,
00054 InputIterator u, OutputIterator res) {
00055 for ( ; l != lend; ++l ) *res++ = *l + (*u++ - *l)*rnd(r);
00056 }
00057
00062 template <typename OutputIterator>
00063 static inline void rnd(DRAND48 * r, int D, OutputIterator res) {
00064 for ( int d = 0; d < D; ++d ) *res++ = rnd(r);
00065 }
00066
00070 static inline bool rndBool(DRAND48 * r, double x) { return rnd(r) < x; }
00071
00075 static inline bool rndBool(DRAND48 * r, double x, double y) {
00076 return rndBool(r, x/(x + y)); }
00077
00081 static inline long rndInt(DRAND48 * r, long x) {
00082 return long(rnd(r, 0.0, double(x))); }
00083
00084 };
00085
00088 }
00089
00090 #endif