From Jason Turner

[rand.util.canonical]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpwck1kwlk/{from.md → to.md} +25 -13
tmp/tmpwck1kwlk/{from.md → to.md} RENAMED
@@ -1,31 +1,43 @@
1
  #### Function template `generate_canonical` <a id="rand.util.canonical">[[rand.util.canonical]]</a>
2
 
3
  ``` cpp
4
- template<class RealType, size_t bits, class URBG>
5
  RealType generate_canonical(URBG& g);
6
  ```
7
 
8
- *Effects:* Invokes `g()` k times to obtain values g₀, …, gₖ₋₁,
9
- respectively. Calculates a quantity
10
- $$S = \sum_{i=0}^{k-1} (g_i - \texttt{g.min()})
11
- \cdot R^i$$ using arithmetic of type `RealType`.
12
 
13
- *Returns:* S / Rᵏ.
 
 
 
 
 
14
 
15
- [*Note 1*: 0 S / Rᵏ < 1. *end note*]
 
 
 
 
 
 
 
 
 
 
16
 
17
  *Throws:* What and when `g` throws.
18
 
19
- *Complexity:* Exactly k = max(1, ⌈ b / log₂ R ⌉) invocations of `g`,
20
- where b[^6]
21
 
22
- is the lesser of `numeric_limits<RealType>::digits` and `bits`, and R is
23
- the value of `g.max()` - `g.min()` + 1.
24
-
25
- [*Note 2*: If the values gᵢ produced by `g` are uniformly distributed,
26
  the instantiation’s results are distributed as uniformly as possible.
27
  Obtaining a value in this way can be a useful step in the process of
28
  transforming a value generated by a uniform random bit generator into a
29
  value that can be delivered by a random number
30
  distribution. — *end note*]
31
 
 
 
 
 
 
1
  #### Function template `generate_canonical` <a id="rand.util.canonical">[[rand.util.canonical]]</a>
2
 
3
  ``` cpp
4
+ template<class RealType, size_t digits, class URBG>
5
  RealType generate_canonical(URBG& g);
6
  ```
7
 
8
+ Let
 
 
 
9
 
10
+ - r be `numeric_limits<RealType>::radix`,
11
+ - R be `g.max()` - `g.min()` + 1,
12
+ - d be the smaller of `digits` and
13
+ `numeric_limits<RealType>::digits`,[^6]
14
+ - k be the smallest integer such that Rᵏ ≥ rᵈ, and
15
+ - x be ⌊ Rᵏ / rᵈ ⌋.
16
 
17
+ An *attempt* is k invocations of `g()` to obtain values g₀, …, gₖ₋₁,
18
+ respectively, and the calculation of a quantity S given by :
19
+
20
+ *Effects:* Attempts are made until S < xrᵈ.
21
+
22
+ [*Note 1*: When R is a power of r, precisely one attempt is
23
+ made. — *end note*]
24
+
25
+ *Returns:* ⌊ S / x ⌋ / rᵈ.
26
+
27
+ [*Note 2*: The return value c satisfies 0 ≤ c < 1. — *end note*]
28
 
29
  *Throws:* What and when `g` throws.
30
 
31
+ *Complexity:* Exactly k invocations of `g` per attempt.
 
32
 
33
+ [*Note 3*: If the values gᵢ produced by `g` are uniformly distributed,
 
 
 
34
  the instantiation’s results are distributed as uniformly as possible.
35
  Obtaining a value in this way can be a useful step in the process of
36
  transforming a value generated by a uniform random bit generator into a
37
  value that can be delivered by a random number
38
  distribution. — *end note*]
39
 
40
+ [*Note 4*: When R is a power of r, an implementation can avoid using an
41
+ arithmetic type that is wider than the output when computing
42
+ S. — *end note*]
43
+