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 0Definition Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h. This function object is an SGI extension; it is not part of the C++ standard. Template parameters None. Model ofRandom Number Generator, Adaptable Unary Function Type requirements None. Public base classesunary_function<unsigned int, unsigned int> Members 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. New members These members are not defined in the Adaptable Unary Function requirements, but are specific to subtractive_rng. 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. Notes
[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.
See alsoRandom Number Generator STL Main PageRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4