|
ALINK="#ff0000">
subtractive_rng
DescriptionSubtractive_rng is a Random Number Generator based on the subtractive method [1]. It is a Unary Function: it takes a single argument N, an unsigned int, and returns an unsigned int that is less than N. Successive calls to the same subtractive_rng object [2] yield a pseudo-random sequence.Exampleint 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 DefinitionDefined 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 parametersNone.Model ofRandom Number Generator, Adaptable Unary FunctionType requirementsNone.Public base classesunary_function<unsigned int, unsigned int>Members
New membersThese members are not defined in the Adaptable Unary Function requirements, but are specific to subtractive_rng.
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 GeneratorCopyright © 1999 Silicon Graphics, Inc. All Rights Reserved. TrademarkInformation
|