Module: Essential Math Group: Statistics classes
RWTRandUniform<Generator>RWTRand<Generator>
#include <rw/rand.h> RWTRandUniform<Generator> gen;
Class RWTRandUniform<Generator> generates random numbers from a uniform distribution in an interval [a, b]. The algorithm used to generate the random numbers begins with random numbers generated from a uniform distribution on the interval [0, 1]. Thus, the speed and statistical properties of the uniform number generator may be changed by varying the Generator template parameter responsible for generating the uniformly distributed numbers.
The class Generator must be a function object whose function call operator returns a uniform random double between 0 and 1. The class RWRandGenerator may be used.
#include <rw/rand.h> #include <iostream.h> #include "myrand.h" int main() { // Create a uniform generator on [0, 1] with an // initial seed value. RWRandGenerator uniform(123456L); // Create a uniform generator on [-1, 1] using the above // generator. RWTRandUniform<RWRandGenerator> uniform(uniform, -1.0, 1.0); // Create a uniform generator on [0 100] using class // RWRandGenerator with a random seed. RWTRandUniform<RWRandGenerator> uniformOne(0.0, 100.0); // Create a uniform generator on [3.14, 345.67] using a // class MyDoubleRand to generate the uniform [0, 1] deviates. RWTRandUniform<MyDoubleRand> myUniform( 3.14, 345.67 ); // Print a few values. for ( int j = 0; j < 10; j++ ) { cout << "uniform [-1, 1] = " << uniform(); cout << "\nuniform [0, 100] = " << uniformOne(); cout << "\nuniform [3.14, 345.67] = " << myUniform()
<< endl; } // Restart one of the generators with another seed value. ( uniformOne.generator() ).restart( 654321L); return 0; }
RWTRandUniform();
Constructs a generator with default range [0, 1].
RWTRandUniform(double a, double b);
Constructs a generator with range [a, b].
RWTRandUniform(const Generator& g, double a = 0, b = 1);
Constructs a generator with underlying uniform [0, 1] generator g and range [a, b]
RWTRandUniform(const RWTRandUniform<Generator>& g);
Constructs self as a copy of g.
double operator()()
Returns the next random number in the sequence.
size_t operator()(double* out, size_t n);
Assigns random numbers to n elements in out. Returns the number of random numbers generated.
double highBound() const;
Returns the upper range value.
double lowBound() const;
Returns the lower range value.
void setRange(double a, double b);
Sets the range to [a, b].
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.