Category: functors | Component type: type |
int main() { subtractive_rng R; for (int i = 0; i < 20; ++i) cout << R(5) << ' '; cout << endl; } // The output is 3 2 3 2 4 3 1 1 2 2 0 3 4 4 4 4 2 1 0 0
Parameter | Description | Default |
---|---|---|
argument_type | Adaptable Unary Function | The type of a subtractive_rng's argument: unsigned int. |
result_type | Adaptable Unary Function | The type of the result: unsigned int. |
subtractive_rng(unsigned int seed) | subtractive_rng | See below. |
subtractive_rng() | subtractive_rng | See below. |
unsigned int operator()(unsigned int N) | Adaptable Unary Function | Function call. Returns a pseudo-random number in the range [0, N). |
void initialize(unsigned int seed) | subtractive_rng | See below. |
Member | Description |
---|---|
subtractive_rng(unsigned int seed) | The constructor. Creates a subtractive_rng whose internal state is initialized using seed. |
subtractive_rng() | The default constructor. Creates a subtractive_rng initialized using a default value. |
void initialize(unsigned int seed) | Re-initializes the internal state of the subtractive_rng, using the value seed. |
[1] See section 3.6 of Knuth for an implementation of the subtractive method in FORTRAN. Section 3.2.2 of Knuth analyzes this class of algorithms. (D. E. Knuth, The Art of Computer Programming. Volume 2: Seminumerical Algorithms, second edition. Addison-Wesley, 1981.)
[2] Note that the sequence produced by a subtractive_rng is completely deterministic, and that the sequences produced by two different subtractive_rng objects are independent of each other. That is: if R1 is a subtractive_rng, then the values returned when R1 is called depend only on R1's seed and on the number of times that R1 has been called. Calls to other subtractive_rng objects are irrelevant. In implementation terms, this is because the class subtractive_rng contains no static members.
Contact Us | Site Map | Trademarks | Privacy | Using this site means you accept its Terms of Use |
Copyright © 2009 - 2017 Silicon Graphics International. All rights reserved. |