From Jason Turner

[alg.random.sample]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpg737dcz5/{from.md → to.md} +47 -0
tmp/tmpg737dcz5/{from.md → to.md} RENAMED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Sample <a id="alg.random.sample">[[alg.random.sample]]</a>
2
+
3
+ ``` cpp
4
+ template<class PopulationIterator, class SampleIterator,
5
+ class Distance, class UniformRandomBitGenerator>
6
+ SampleIterator sample(PopulationIterator first, PopulationIterator last,
7
+ SampleIterator out, Distance n,
8
+ UniformRandomBitGenerator&& g);
9
+ ```
10
+
11
+ *Requires:*
12
+
13
+ - `PopulationIterator` shall satisfy the requirements of an input
14
+ iterator ([[input.iterators]]).
15
+ - `SampleIterator` shall satisfy the requirements of an output
16
+ iterator ([[output.iterators]]).
17
+ - `SampleIterator` shall satisfy the additional requirements of a random
18
+ access iterator ([[random.access.iterators]]) unless
19
+ `PopulationIterator` satisfies the additional requirements of a
20
+ forward iterator ([[forward.iterators]]).
21
+ - `PopulationIterator`’s value type shall be
22
+ writable ([[iterator.requirements.general]]) to `out`.
23
+ - `Distance` shall be an integer type.
24
+ - `remove_reference_t<UniformRandomBitGenerator>` shall meet the
25
+ requirements of a uniform random bit generator type
26
+ ([[rand.req.urng]]) whose return type is convertible to `Distance`.
27
+ - `out` shall not be in the range \[`first`, `last`).
28
+
29
+ *Effects:* Copies `min(last - first, n)` elements (the *sample*) from
30
+ \[`first`, `last`) (the *population*) to `out` such that each possible
31
+ sample has equal probability of appearance.
32
+
33
+ [*Note 1*: Algorithms that obtain such effects include *selection
34
+ sampling* and *reservoir sampling*. — *end note*]
35
+
36
+ *Returns:* The end of the resulting sample range.
37
+
38
+ *Complexity:* 𝑂(`last - first`).
39
+
40
+ *Remarks:*
41
+
42
+ - Stable if and only if `PopulationIterator` satisfies the requirements
43
+ of a forward iterator.
44
+ - To the extent that the implementation of this function makes use of
45
+ random numbers, the object `g` shall serve as the implementation’s
46
+ source of randomness.
47
+