The type of the Random Number Generator's argument. This must be an integral type.
Result type The type returned when the Random Number Generator is called. It must be the same as the argument type.
Notation

F A type that is a model of Random Number Generator.

Integer The argument type of F.

f Object of type F.

N Object of type Integer

Definitions

The domain of a Random Number Generator (i.e. the set of permissible values for its argument) is the set of numbers that are greater than zero and less than some maximum value.

The range of a Random Number Generator is the set of nonnegative integers that are less than the Random Number Generator's argument.

Valid expressions

None, except for those defined by Unary Function.

Expression semantics
Name Expression Precondition Semantics Postcondition
Function call f(N) N is positive. Returns a pseudo-random number of type Integer. [2] The return value is less than N , and greater than or equal to 0.
Invariants
Uniformity In the limit as f is called many times with the same argument N, every integer in the range [0, N) will appear an equal number of times.
Notes

[1] Uniform distribution means that all of the numbers in the range [0, N) appear with equal frequency. Or, to put it differently, the probability for obtaining any particular value is 1/N.

[2] Random number generators are a very subtle subject: a good random number generator must satisfy many statistical properties beyond uniform distribution. See section 3.4 of Knuth for a discussion of what it means for a sequence to be random, and section 3.2 for several algorithms that may be used to write random number generators. (D. E. Knuth, The Art of Computer Programming. Volume 2: Seminumerical Algorithms, third edition. Addison-Wesley, 1998.)

Predefined function objects

Arithmetic operations

plus<T>

Category: functors

Component type: type

Description

Plus<T> is a function object. Specifically, it is an Adaptable Binary Function. If f is an object of class plus<T> and x and y are objects of class T, then f(x,y) returns x+y.

Example

Each element in V3 will be the sum of the corresponding elements in V1 and V2

const int N = 1000;

vector<double> V1(N);

vector<double> V2(N);

vector<double> V3(N);

iota(V1.begin(), V1.end(), 1);

fill(V2.begin(), V2.end(), 75);

assert(V2.size() >= V1.size() && V3.size() >= V1.size());

transform(V1.begin(), V1.end(), V2.begin(), V3.begin(), plus<double>());

Definition

Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h.

Template parameters
Parameter Description
T
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату