Debian Codegraph @

src/ITGSend/newran/newran.h

raw symbols SCIP
1 /// \defgroup newran Newran random number generator library
2 ///@{
3
4 /// \file newran.h
5 /// Definition file for random number generator library.
6
7 #ifndef NEWRAN_LIB
8 #define NEWRAN_LIB 0
9
10 //******************* utilities and definitions *************************
11
12 #include "include.h"
13 #include "myexcept.h"
14 #include "extreal.h"
15 #include "simpstr.h"
16
17 #ifdef use_namespace
18 namespace NEWRAN { using namespace RBD_COMMON; }
19 namespace RBD_LIBRARIES { using namespace NEWRAN; }
20 namespace NEWRAN {
21 using RBD_COMMON::Real;
22 using RBD_COMMON::long_Real;
23 #endif
24
25 /// Probability function (Real function of Real variable).
26 typedef Real (*PDF)(Real);
27
28 // for log gamma function
29 Real gamma_series(long_Real z);
30 inline Real gamma_g_value() { return 10.0; }
31 Real ln_gamma(Real z, int& sign);
32 Real ln_gamma(Real z);
33 Real ln_gamma_lanczos(Real z);
34 Real rbd_gamma(Real z);
35
36
37 class RepeatedRandom;
38 class SelectedRandom;
39
40 /// Base for random number classes.
41 class Random // uniform random number generator
42 {
43
44 private:
45 void operator=(const Random&) {} // private so can't access
46
47 virtual void CSFD(bool update) {}
48 virtual void CSTD() {}
49
50 protected:
51 static Random* RNG; // pointer to uniform rng
52 static Random* Dummy; // pointer to dummy rng
53 static SimpleString Dir; // directory where seed is stored
54
55 public:
56 static void Set(Random& r); // set type
57 static void CopySeedFromDisk(bool update=false);
58 static void CopySeedToDisk();
59 static void SetDirectory(const char* dir); // set the directory for storing seed
60
61 virtual Real Next() { return RNG->Next(); } // get new value
62 virtual unsigned long ulNext(); // unsigned long value
63 virtual const char* Name(); // identification
64 virtual Real Density(Real) const; // used by PosGen & Asymgen
65 Random() {} // do nothing
66 virtual ~Random() {} // make destructors virtual
67 SelectedRandom& operator()(double); // used by MixedRandom
68 RepeatedRandom& operator()(int); // for making combinations
69 virtual ExtReal Mean() const { return 0.5; }
70 // mean of distribution
71 virtual ExtReal Variance() const { return 1.0/12.0; }
72 // variance of distribution
73 virtual void tDelete() {} // delete components of sum
74 virtual int nelems() const { return 1; }
75 // used by MixedRandom
76 virtual void load(int*,Real*,Random**);
77 friend class RandomPermutation;
78 };
79
80 /// Base for Lewis Goodman Miller generators.
81 /// \internal
82 class LGM_base : public Random
83 {
84 void operator=(const LGM_base&) {} // private so can't access
85 protected:
86 long seed;
87 void NextValue();
88 bool Update; // true if update seed on disk
89
90 public:
91 LGM_base(double s); // seed between 0 and 1
92 Real Next(); // get new value
93 unsigned long ulNext(); // new unsigned long value
94 const char* Name(); // identification
95 };
96
97 /// Lewis Goodman Miller generator with no mixing.
98 class LGM_simple : public LGM_base
99 {
100 void operator=(const LGM_simple&) {} // private so can't access
101 void CSFD(bool update);
102 void CSTD();
103
104 public:
105 LGM_simple(double s=0.46875); // seed between 0 and 1
106 const char* Name(); // identification
107 ~LGM_simple();
108 };
109
110 /// Lewis Goodman Miller generator with mixing.
111 class LGM_mixed : public LGM_base
112 {
113 long Buffer[128]; // for mixing random numbers
114 void NextValue();
115 long seed_mixed;
116 void operator=(const LGM_mixed&) {} // private so can't access
117 void CSFD(bool update);
118 void CSTD();
119
120 public:
121 LGM_mixed(double s=0.46875); // s between 0 and 1
122 Real Next(); // get new value
123 unsigned long ulNext(); // new unsigned long value
124 const char* Name(); // identification
125 ~LGM_mixed();
126 };
127
128 /// Wichmann Hill generator.
129 class WH : public Random
130 {
131 bool Update; // true if update seed on disk
132 void operator=(const WH&) {} // private so can't access
133 unsigned long seed1, seed2, seed3;
134 void CSFD(bool update);
135 void CSTD();
136
137 public:
138 WH(double s=0.46875); // seed between 0 and 1
139 Real Next(); // get new value
140 unsigned long ulNext(); // new unsigned long value
141 const char* Name(); // identification
142 ~WH();
143 };
144
145 /// Fishman Moore generator.
146 class FM : public Random
147 {
148 bool Update; // true if update seed on disk
149 void operator=(const FM&) {} // private so can't access
150 unsigned long seed;
151 void NextValue();
152 void CSFD(bool update);
153 void CSTD();
154
155 public:
156 FM(double s=0.46875); // s between 0 and 1
157 Real Next();
158 unsigned long ulNext(); // new unsigned long value
159 const char* Name(); // identification
160 ~FM();
161 };
162
163 /// Marsaglia's mother of all generators.
164 class MotherOfAll : public Random
165 {
166 bool Update; // true if update seed on disk
167 short mother1[10];
168 short mother2[10];
169 short mStart;
170 unsigned long seed;
171 void Mother();
172 void operator=(const MotherOfAll&) {} // private so can't access
173 void CSFD(bool update);
174 void CSTD();
175
176 public:
177 MotherOfAll(double s=0.9375);
178 Real Next();
179 unsigned long ulNext(); // new unsigned long value
180 const char* Name();
181 ~MotherOfAll();
182 };
183
184 /// Marsaglia's multiply with carry generator.
185 class MultWithCarry : public Random
186 {
187 bool Update; // true if update seed on disk
188 unsigned long x;
189 unsigned long crry;
190
191 void NextValue();
192
193 void operator=(MultWithCarry&) {} // private so can't access
194 void CSFD(bool update);
195 void CSTD();
196
197 public:
198 MultWithCarry(double s=0.46875);
199 Real Next();
200 unsigned long ulNext(); // new unsigned long value
201 const char* Name();
202 ~MultWithCarry();
203 };
204
205 /// Mersenne Twister generator.
206 class MT : public Random
207 {
208 bool Update; // true if update seed on disk
209 void init_genrand(unsigned long s);
210 unsigned long genrand_int32();
211 void operator=(const MT&) {} // private so can't access
212 void CSFD(bool update);
213 void CSTD();
214
215 public:
216 MT(double s=0.46875);
217 Real Next();
218 unsigned long ulNext() { return genrand_int32(); }
219 const char* Name();
220 ~MT();
221 };
222
223 /// Dummy RNG for returning an error message when RNG not setup.
224 /// \internal
225 class DummyRNG : public Random
226 {
227 void operator=(const DummyRNG&) {} // private so can't access
228 void CSFD(bool update);
229 void CSTD();
230
231 public:
232 Real Next();
233 const char* Name();
234 };
235
236
237 /// Uniform random number generator.
238 class Uniform : public Random
239 {
240 void operator=(const Uniform&) {} // private so can't access
241
242 public:
243 const char* Name(); // identification
244 Uniform() {} // set value
245 Real Next() { return RNG->Next(); }
246 ExtReal Mean() const { return 0.5; }
247 ExtReal Variance() const { return 1.0/12.0; }
248 Real Density(Real x) const { return (x < 0.0 || x > 1.0) ? 0 : 1.0; }
249 };
250
251 /// Return a constant.
252 class Constant : public Random
253 {
254 void operator=(const Constant&) {} // private so can't access
255 Real value; // value to be returned
256
257 public:
258 const char* Name(); // identification
259 Constant(Real v) { value=v; } // set value
260 Real Next() { return value; }
261 ExtReal Mean() const { return value; }
262 ExtReal Variance() const { return 0.0; }
263 };
264
265 /// Automatic generator for positive random variables.
266 class PosGen : public Random // generate positive rv
267 {
268 void operator=(const PosGen&) {} // private so can't access
269
270 protected:
271 Real xi, *sx, *sfx;
272 bool NotReady;
273 void Build(bool); // called on first call to Next
274
275 public:
276 const char* Name(); // identification
277 PosGen(); // constructor
278 ~PosGen(); // destructor
279 Real Next(); // to get a single new value
280 ExtReal Mean() const { return (ExtReal)Missing; }
281 ExtReal Variance() const { return (ExtReal)Missing; }
282 };
283
284 /// Automatic generator for symmetric random variables.
285 class SymGen : public PosGen // generate symmetric rv
286 {
287 void operator=(const SymGen&) {} // private so can't access
288
289 public:
290 const char* Name(); // identification
291 Real Next(); // to get a single new value
292 };
293
294 /// Normal random number generator.
295 class Normal : public SymGen // generate standard normal rv
296 {
297 void operator=(const Normal&) {} // private so can't access
298 static Real Nxi, *Nsx, *Nsfx; // so we need initialise only once
299 static long count; // assume initialised to 0
300
301 public:
302 const char* Name(); // identification
303 Normal();
304 ~Normal();
305 Real Density(Real) const; // normal density function
306 ExtReal Mean() const { return 0.0; }
307 ExtReal Variance() const { return 1.0; }
308 };
309
310 /// Chi-squared (central) random number generator.
311 class ChiSq : public Random // generate non-central chi-sq rv
312 {
313 void operator=(const ChiSq&) {} // private so can't access
314 Random* c1; // pointers to generators
315 Random* c2; // pointers to generators
316 int version; // indicates method of generation
317 Real mean, var;
318
319 public:
320 const char* Name(); // identification
321 ChiSq(int, Real=0.0); // df and non-centrality parameter
322 ~ChiSq();
323 ExtReal Mean() const { return mean; }
324 ExtReal Variance() const { return var; }
325 Real Next();
326 };
327
328 /// Cauchy random number generator.
329 class Cauchy : public SymGen // generate standard cauchy rv
330 {
331 void operator=(const Cauchy&) {} // private so can't access
332
333 public:
334 const char* Name(); // identification
335 Real Density(Real) const; // Cauchy density function
336 ExtReal Mean() const { return Indefinite; }
337 ExtReal Variance() const { return PlusInfinity; }
338 };
339
340 ///Exponential random number generator
341
342 class Exponential : public Uniform
343 {
344 Uniform U;
345 double mean;
346 double variance;
347
348 public:
349
350 Exponential(double md=1):mean(md){}
351 Real Next();
352 const char* Name(); // identification
353 Real Density(Real) const; // Exponential density function
354 ExtReal Mean() const { return mean; }
355 ExtReal Variance() const { return mean*mean; }
356 };
357 /// Weibull random generator
358 class Weibull : public Uniform
359 {
360 Uniform U;
361 double scale;
362 double shape;
363 public:
364 Weibull(double scale_, double shape_)
365 {
366 scale = scale_;
367 shape = shape_;
368 }
369 Real Next();
370 const char* Name();
371 };
372
373 /// Extreme_Largest random generator
374 class Extreme_Largest : public Uniform
375 {
376 Uniform U;
377 double mu;
378 double sigma;
379 public:
380 Extreme_Largest(double mu_, double sigma_)
381 {
382 mu = mu_;
383 sigma = sigma_;
384 }
385 Real Next();
386 const char* Name();
387 };
388
389 /// T-Student
390 class Student : public Uniform
391 {
392 private:
393 Real mu;
394 Real sigma;
395 Real nu;
396
397 public:
398 Student(Real mu_, Real sigma_, Real nu_)
399 {
400 mu = mu_;
401 sigma = sigma_;
402 nu=nu_;
403 }
404 Real Next();
405 const char* Name();
406 };
407
408 /// Automatic asymmetric random number generator.
409 class AsymGen : public Random // generate asymmetric rv
410 {
411 void operator=(const AsymGen&) {} // private so can't access
412 Real xi, *sx, *sfx; int ic;
413 bool NotReady;
414 void Build(); // called on first call to Next
415
416 protected:
417 Real mode;
418
419 public:
420 const char* Name(); // identification
421 AsymGen(Real); // constructor (Real=mode)
422 ~AsymGen(); // destructor
423 Real Next(); // to get a single new value
424 ExtReal Mean() const { return (ExtReal)Missing; }
425 ExtReal Variance() const { return (ExtReal)Missing; }
426 };
427
428 /// Gamma random number generator.
429 class Gamma : public Random // generate gamma rv
430 {
431 void operator=(const Gamma&) {} // private so can't access
432 Random* method;
433
434 public:
435 const char* Name(); // identification
436 Gamma(Real); // constructor (Real=shape)
437 ~Gamma() { delete method; }
438 Real Next() { return method->Next(); }
439 ExtReal Mean() const { return method->Mean(); }
440 ExtReal Variance() const { return method->Variance(); }
441 };
442
443 /// Generator for positive rngs where we have a pointer to the density.
444 class PosGenX : public PosGen
445 {
446 void operator=(const PosGenX&) {} // private so can't access
447 PDF f;
448
449 public:
450 const char* Name(); // identification
451 PosGenX(PDF fx);
452 Real Density(Real x) const { return (*f)(x); }
453 };
454
455 /// Generator for symmetric rngs where we have a pointer to the density.
456 class SymGenX : public SymGen
457 {
458 void operator=(const SymGenX&) {} // private so can't access
459 PDF f;
460
461 public:
462 const char* Name(); // identification
463 SymGenX(PDF fx);
464 Real Density(Real x) const { return (*f)(x); }
465 };
466
467 /// Generator for asymmetric rngs where we have a pointer to the density.
468 class AsymGenX : public AsymGen
469 {
470 void operator=(const AsymGenX&) {} // private so can't access
471 PDF f;
472
473 public:
474 const char* Name(); // identification
475 AsymGenX(PDF fx, Real mx);
476 Real Density(Real x) const { return (*f)(x); }
477 };
478
479 /// Pareto random number generator.
480 /// Use definition of Kotz and Johnson: "Continuous univariate distributions 1",
481 /// chapter 19 with k = 1.
482 class Pareto : public Random
483 {
484 void operator=(const Pareto&) {} // private so can't access
485 Real Shape, RS;
486
487 public:
488 const char* Name(); // identification
489 Pareto(Real shape); // constructor (Real=shape)
490 ~Pareto() {}
491 Real Next();
492 ExtReal Mean() const;
493 ExtReal Variance() const;
494 };
495
496 /// Discrete random number generator.
497 class DiscreteGen : public Random
498 {
499 void operator=(const DiscreteGen&) {} // private so can't access
500 Real *p; int *ialt; int n; Real *val;
501 void Gen(int, Real*); // called by constructors
502 Real mean, var; // calculated by the constructor
503
504 public:
505 const char* Name(); // identification
506 DiscreteGen(int,Real*); // constructor
507 DiscreteGen(int,Real*,Real*); // constructor
508 ~DiscreteGen(); // destructor
509 Real Next(); // new single value
510 ExtReal Mean() const { return mean; }
511 ExtReal Variance() const { return var; }
512 };
513
514 /// Poisson random number generator.
515 class Poisson : public Random // generate poisson rv
516 {
517 void operator=(const Poisson&) {} // private so can't access
518 Random* method;
519
520 public:
521 const char* Name(); // identification
522 Poisson(Real); // constructor (Real=mean)
523 ~Poisson() { delete method; }
524 Real Next() { return method->Next(); }
525 ExtReal Mean() const { return method->Mean(); }
526 ExtReal Variance() const { return method->Variance(); }
527 };
528
529 /// Binomial random number generator.
530 class Binomial : public Random // generate binomial rv
531 {
532 void operator=(const Binomial&) {} // private so can't access
533 Random* method;
534
535 public:
536 const char* Name(); // identification
537 Binomial(int p, Real n); // constructor (int=n, Real=p)
538 ~Binomial() { delete method; }
539 Real Next() { return method->Next(); }
540 ExtReal Mean() const { return method->Mean(); }
541 ExtReal Variance() const { return method->Variance(); }
542 };
543
544 /// Negative binomial random number generator.
545 class NegativeBinomial : public AsymGen // generate negative binomial rv
546 {
547 Real N, P, Q, p, ln_q, c;
548
549 public:
550 const char* Name();
551 NegativeBinomial(Real NX, Real PX); // constructor
552 Real Density(Real) const; // Negative binomial density function
553 Real Next();
554 ExtReal Mean() const { return N * P; }
555 ExtReal Variance() const { return N * P * Q; }
556 };
557
558 /// Stable random number generator.
559 class Stable : public Random
560 {
561 public:
562 enum Notation { Chambers, Standard, Kalpha, Default };
563 private:
564 Real alpha, bprime;
565 Real beta;
566 Notation notation;
567 Real d2(Real z);
568 Real tan2(Real x);
569 Real k(Real a);
570 const Real piby2;
571 const Real piby4;
572
573 public:
574 const char* Name();
575 Stable(Real a, Real bx, Notation n = Default);
576 Real Next();
577 ExtReal Mean() const;
578 ExtReal Variance() const;
579 Real beta_prime() const { return bprime; }
580 };
581
582
583 // ***************** Simple functions of random variables *********************
584
585 /// Negative of a random variable.
586 /// \internal
587 class NegatedRandom : public Random
588 {
589 protected:
590 Random* rv;
591 NegatedRandom(Random& rvx) : rv(&rvx) {}
592 void tDelete() { rv->tDelete(); delete this; }
593
594 public:
595 Real Next();
596 ExtReal Mean() const;
597 ExtReal Variance() const;
598 friend NegatedRandom& operator-(Random&);
599 };
600
601 /// Scaled version of a random variable.
602 /// \internal
603 class ScaledRandom : public Random
604 {
605 protected:
606 Random* rv; Real s;
607 ScaledRandom(Random& rvx, Real sx) : rv(&rvx), s(sx) {}
608 void tDelete() { rv->tDelete(); delete this; }
609
610 public:
611 Real Next();
612 ExtReal Mean() const;
613 ExtReal Variance() const;
614 friend ScaledRandom& operator*(Real, Random&);
615 friend ScaledRandom& operator*(Random&, Real);
616 friend ScaledRandom& operator/(Random&, Real);
617 };
618
619 /// Reciprocal of a random variable.
620 /// \internal
621 class ReciprocalRandom : public Random
622 {
623 protected:
624 Random* rv; Real s;
625 ReciprocalRandom(Random& rvx, Real sx) : rv(&rvx), s(sx) {}
626 void tDelete() { rv->tDelete(); delete this; }
627
628 public:
629 Real Next();
630 ExtReal Mean() const { return Missing; }
631 ExtReal Variance() const { return Missing; }
632 friend ReciprocalRandom& operator/(Real, Random&);
633 };
634
635 /// Random variable plus a constant.
636 /// \internal
637 class ShiftedRandom : public ScaledRandom
638 {
639 ShiftedRandom(Random& rvx, Real sx) : ScaledRandom(rvx, sx) {}
640
641 public:
642 Real Next();
643 ExtReal Mean() const;
644 ExtReal Variance() const;
645 friend ShiftedRandom& operator+(Real, Random&);
646 friend ShiftedRandom& operator+(Random&, Real);
647 friend ShiftedRandom& operator-(Random&, Real);
648 };
649
650 /// Constant minus a random variable.
651 /// \internal
652 class ReverseShiftedRandom : public ScaledRandom
653 {
654 ReverseShiftedRandom(Random& rvx, Real sx) : ScaledRandom(rvx, sx) {}
655
656 public:
657 Real Next();
658 ExtReal Mean() const;
659 ExtReal Variance() const;
660 friend ReverseShiftedRandom& operator-(Real, Random&);
661 };
662
663 /// Sum of iid random variables.
664 /// \internal
665 class RepeatedRandom : public Random
666 {
667 Random* rv; int n;
668 void tDelete() { rv->tDelete(); delete this; }
669 RepeatedRandom(Random& rvx, int nx) : rv(&rvx), n(nx) {}
670
671 public:
672 Real Next();
673 ExtReal Mean() const;
674 ExtReal Variance() const;
675 friend class Random;
676 };
677
678 /// Product of two random variables.
679 /// \internal
680 class MultipliedRandom : public Random
681 {
682 protected:
683 Random* rv1; Random* rv2;
684 void tDelete() { rv1->tDelete(); rv2->tDelete(); delete this; }
685 MultipliedRandom(Random& rv1x, Random& rv2x) : rv1(&rv1x), rv2(&rv2x) {}
686
687 public:
688 Real Next();
689 ExtReal Mean() const;
690 ExtReal Variance() const;
691 friend MultipliedRandom& operator*(Random&, Random&);
692 };
693
694 /// Sum of two random variables.
695 /// \internal
696 class AddedRandom : public MultipliedRandom
697 {
698 AddedRandom(Random& rv1x, Random& rv2x) : MultipliedRandom(rv1x, rv2x) {}
699
700 public:
701 Real Next();
702 ExtReal Mean() const;
703 ExtReal Variance() const;
704 friend AddedRandom& operator+(Random&, Random&);
705 };
706
707 /// Difference of random variables.
708 /// \internal
709 class SubtractedRandom : public MultipliedRandom
710 {
711 SubtractedRandom(Random& rv1x, Random& rv2x)
712 : MultipliedRandom(rv1x, rv2x) {}
713
714 public:
715 Real Next();
716 ExtReal Mean() const;
717 ExtReal Variance() const;
718 friend SubtractedRandom& operator-(Random&, Random&);
719 };
720
721 /// Ratio of random variables.
722 /// \internal
723 class DividedRandom : public MultipliedRandom
724 {
725 DividedRandom(Random& rv1x, Random& rv2x)
726 : MultipliedRandom(rv1x, rv2x) {}
727
728 public:
729 Real Next();
730 ExtReal Mean() const { return Missing; }
731 ExtReal Variance() const { return Missing; }
732 friend DividedRandom& operator/(Random&, Random&);
733 };
734
735 /// Sum of random variables.
736 class SumRandom : public Random
737 {
738 void operator=(const SumRandom&) {} // private so can't access
739 Random* rv;
740
741 public:
742 const char* Name(); // identification
743 SumRandom(NegatedRandom& rvx) : rv(&rvx) {}
744 SumRandom(AddedRandom& rvx) : rv(&rvx) {}
745 SumRandom(MultipliedRandom& rvx) : rv(&rvx) {}
746 SumRandom(SubtractedRandom& rvx) : rv(&rvx) {}
747 SumRandom(DividedRandom& rvx) : rv(&rvx) {}
748 SumRandom(ShiftedRandom& rvx) : rv(&rvx) {}
749 SumRandom(ReverseShiftedRandom& rvx) : rv(&rvx) {}
750 SumRandom(ScaledRandom& rvx) : rv(&rvx) {}
751 SumRandom(ReciprocalRandom& rvx) : rv(&rvx) {}
752 SumRandom(RepeatedRandom& rvx) : rv(&rvx) {}
753 Real Next() { return rv->Next(); }
754 ExtReal Mean() const { return rv->Mean(); }
755 ExtReal Variance() const { return rv->Variance(); }
756 ~SumRandom() { rv->tDelete(); }
757 };
758
759 // ******************** Mixtures of random numbers ************************
760
761 /// Random variable and mixture probability.
762 /// \internal
763 class SelectedRandom : public Random
764 {
765 friend class Random;
766 Random* rv; Real p;
767 SelectedRandom(Random& rvx, Real px) : rv(&rvx), p(px) {}
768 void tDelete() { rv->tDelete(); delete this; }
769
770 public:
771 void load(int*, Real*, Random**);
772 Real Next();
773 };
774
775 /// Sum of two random variables with mixture probabilities.
776 /// \internal
777 class AddedSelectedRandom : public Random
778 {
779 friend class Random;
780
781 protected:
782 Random* rv1; Random* rv2;
783 AddedSelectedRandom(Random& rv1x, Random& rv2x)
784 : rv1(&rv1x), rv2(&rv2x) {}
785 void tDelete() { rv1->tDelete(); rv2->tDelete(); delete this; }
786
787 public:
788 int nelems() const;
789 void load(int*, Real*, Random**);
790 Real Next();
791 friend AddedSelectedRandom& operator+(SelectedRandom&,
792 SelectedRandom&);
793 friend AddedSelectedRandom& operator+(AddedSelectedRandom&,
794 SelectedRandom&);
795 friend AddedSelectedRandom& operator+(SelectedRandom&,
796 AddedSelectedRandom&);
797 friend AddedSelectedRandom& operator+(AddedSelectedRandom&,
798 AddedSelectedRandom&);
799 };
800
801 /// Mixtures of random numbers.
802 class MixedRandom : public Random
803 {
804 void operator=(const MixedRandom&) {} // private so can't access
805 int n; // number of components
806 DiscreteGen* dg; // discrete mixing distribution
807 Random** rv; // array of pointers to rvs
808 ExtReal mean, var;
809 void Build(Real*); // used by constructors
810
811 public:
812 const char* Name(); // identification
813 MixedRandom(int, Real*, Random**);
814 MixedRandom(AddedSelectedRandom&);
815 ~MixedRandom();
816 Real Next();
817 ExtReal Mean() const { return mean; }
818 ExtReal Variance() const { return var; }
819 };
820
821 /// Generate random permutation.
822 class RandomPermutation
823 {
824 Random U;
825
826 public:
827 void Next(int N, int M, int p[], int start = 0);
828 // select permutation of M numbers
829 // from start, ..., start+N-1
830 // results to p
831 void Next(int N, int p[], int start = 0) { Next(N, N, p, start); }
832 };
833
834 /// Generate random combination.
835 /// Result is sorted in ascending order
836 class RandomCombination : public RandomPermutation
837 {
838 void SortAscending(int n, int gm[]);
839
840 public:
841 void Next(int N, int M, int p[], int start = 0)
842 { RandomPermutation::Next(N, M, p, start); SortAscending(M, p); }
843 void Next(int N, int p[], int start = 0) { Next(N, N, p, start); }
844 };
845
846 /// Poisson random variable - select parameter when called.
847 class VariPoisson
848 {
849 Uniform U;
850 Normal N;
851 Poisson P100;
852 Poisson P200;
853 Real Next_very_small(Real mu);
854 Real Next_small(Real mu);
855 Real Next_large(Real mu);
856 public:
857 VariPoisson();
858 int iNext(Real mu);
859 Real Next(Real mu);
860 };
861
862 /// Binomial random variable - select parameters when called.
863 class VariBinomial
864 {
865 Uniform U;
866 Normal N;
867 Real Next_very_small(int n, Real p);
868 Real Next_small(int n, Real p);
869 Real Next_large(int n, Real p);
870 public:
871 VariBinomial();
872 int iNext(int n, Real p);
873 Real Next(int n, Real p);
874 };
875
876 /// Log normal random variable - select parameters when called.
877 class VariLogNormal
878 {
879 Normal N;
880 public:
881 VariLogNormal() {}
882 Real Next(Real mean, Real sd);
883 };
884
885 // friend functions declared again outside class definitions
886 NegatedRandom& operator-(Random&);
887 ScaledRandom& operator*(Real, Random&);
888 ScaledRandom& operator*(Random&, Real);
889 ScaledRandom& operator/(Random&, Real);
890 ReciprocalRandom& operator/(Real, Random&);
891 ShiftedRandom& operator+(Real, Random&);
892 ShiftedRandom& operator+(Random&, Real);
893 ShiftedRandom& operator-(Random&, Real);
894 ReverseShiftedRandom& operator-(Real, Random&);
895 MultipliedRandom& operator*(Random&, Random&);
896 AddedRandom& operator+(Random&, Random&);
897 SubtractedRandom& operator-(Random&, Random&);
898 DividedRandom& operator/(Random&, Random&);
899 AddedSelectedRandom& operator+(SelectedRandom&, SelectedRandom&);
900 AddedSelectedRandom& operator+(AddedSelectedRandom&, SelectedRandom&);
901 AddedSelectedRandom& operator+(SelectedRandom&, AddedSelectedRandom&);
902 AddedSelectedRandom& operator+(AddedSelectedRandom&, AddedSelectedRandom&);
903
904
905
906
907 #ifdef use_namespace
908 }
909 #endif
910
911 #endif
912
913 // body file: newran1.cpp
914 // body file: newran2.cpp
915
916 ///@}
917