From Jason Turner

[rand]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjly6snfr/{from.md → to.md} +330 -308
tmp/tmpjly6snfr/{from.md → to.md} RENAMED
@@ -2,19 +2,21 @@
2
 
3
  This subclause defines a facility for generating (pseudo-)random
4
  numbers.
5
 
6
  In addition to a few utilities, four categories of entities are
7
- described: *uniform random number generators*, *random number engines*,
8
  *random number engine adaptors*, and *random number distributions*.
9
  These categorizations are applicable to types that satisfy the
10
  corresponding requirements, to objects instantiated from such types, and
11
- to templates producing such types when instantiated. These entities are
12
- specified in such a way as to permit the binding of any uniform random
13
- number generator object `e` as the argument to any random number
14
- distribution object `d`, thus producing a zero-argument function object
15
- such as given by `bind(d,e)`.
 
 
16
 
17
  Each of the entities specified via this subclause has an associated
18
  arithmetic type ([[basic.fundamental]]) identified as `result_type`.
19
  With `T` as the `result_type` thus associated with such an entity, that
20
  entity is characterized:
@@ -36,75 +38,78 @@ Throughout this subclause [[rand]], the effect of instantiating a
36
  template:
37
 
38
  Throughout this subclause [[rand]], phrases of the form “`x` is an
39
  iterator of a specific kind” shall be interpreted as equivalent to the
40
  more formal requirement that “`x` is a value of a type satisfying the
41
- requirements of the specified iterator type.
42
 
43
  Throughout this subclause [[rand]], any constructor that can be called
44
  with a single argument and that satisfies a requirement specified in
45
  this subclause shall be declared `explicit`.
46
 
47
  #### Seed sequence requirements <a id="rand.req.seedseq">[[rand.req.seedseq]]</a>
48
 
49
  A *seed sequence* is an object that consumes a sequence of
50
  integer-valued data and produces a requested number of unsigned integer
51
- values i, 0 ≤ i < 2³², based on the consumed data. Such an object
52
- provides a mechanism to avoid replication of streams of random variates.
53
- This can be useful, for example, in applications requiring large numbers
54
- of random number engines.
 
 
55
 
56
  A class `S` satisfies the requirements of a seed sequence if the
57
  expressions shown in Table  [[tab:SeedSequence]] are valid and have the
58
  indicated semantics, and if `S` also satisfies all other requirements of
59
  this section [[rand.req.seedseq]]. In that Table and throughout this
60
  section:
61
 
62
- #### Uniform random number generator requirements <a id="rand.req.urng">[[rand.req.urng]]</a>
63
 
64
- A *uniform random number generator* `g` of type `G` is a function object
65
  returning unsigned integer values such that each value in the range of
66
- possible results has (ideally) equal probability of being returned. The
67
- degree to which `g`’s results approximate the ideal is often determined
68
- statistically.
69
 
70
- A class `G` satisfies the requirements of a *uniform random number
 
 
 
71
  generator* if the expressions shown in Table 
72
- [[tab:UniformRandomNumberGenerator]] are valid and have the indicated
73
  semantics, and if `G` also satisfies all other requirements of this
74
  section [[rand.req.urng]]. In that Table and throughout this section:
75
 
76
  The following relation shall hold: `G::min() < G::max()`.
77
 
78
  #### Random number engine requirements <a id="rand.req.eng">[[rand.req.eng]]</a>
79
 
80
  A *random number engine* (commonly shortened to *engine*) `e` of type
81
- `E` is a uniform random number generator that additionally meets the
82
- requirements (*e.g.*, for seeding and for input/output) specified in
83
- this section.
84
 
85
  At any given time, `e` has a state eᵢ for some integer i ≥ 0. Upon
86
  construction, `e` has an initial state e₀. An engine’s state may be
87
  established via a constructor, a `seed` function, assignment, or a
88
  suitable `operator>>`.
89
 
90
  `E`’s specification shall define:
91
 
92
- A class `E` that satisfies the requirements of a uniform random number
93
  generator ([[rand.req.urng]]) also satisfies the requirements of a
94
  *random number engine* if the expressions shown in Table 
95
  [[tab:RandomEngine]] are valid and have the indicated semantics, and if
96
  `E` also satisfies all other requirements of this section
97
  [[rand.req.eng]]. In that Table and throughout this section:
98
 
99
  where `charT` and `traits` are constrained according to Clause 
100
  [[strings]] and Clause  [[input.output]].
101
 
102
  `E` shall meet the requirements of `CopyConstructible` (Table 
103
- [[copyconstructible]]) and `CopyAssignable` (Table  [[copyassignable]])
104
- types. These operations shall each be of complexity no worse than
105
- 𝑂(\mbox{size of state}).
106
 
107
  #### Random number engine adaptor requirements <a id="rand.req.adapt">[[rand.req.adapt]]</a>
108
 
109
  A *random number engine adaptor* (commonly shortened to *adaptor*) `a`
110
  of type `A` is a random number engine that takes values produced by some
@@ -136,11 +141,11 @@ A::A(result_type s);
136
  ```
137
 
138
  *Effects:* The base engine is initialized with `s`.
139
 
140
  ``` cpp
141
- template<class Sseq> void A::A(Sseq& q);
142
  ```
143
 
144
  *Effects:* The base engine is initialized with `q`.
145
 
146
  ``` cpp
@@ -188,12 +193,12 @@ In that Table and throughout this section,
188
 
189
  where `charT` and `traits` are constrained according to Clauses 
190
  [[strings]] and [[input.output]].
191
 
192
  `D` shall satisfy the requirements of `CopyConstructible` (Table 
193
- [[copyconstructible]]) and `CopyAssignable` (Table  [[copyassignable]])
194
- types.
195
 
196
  The sequence of numbers produced by repeated invocations of `d(g)` shall
197
  be independent of any invocation of `os << d` or of any `const` member
198
  function of `D` between any of the invocations `d(g)`.
199
 
@@ -207,12 +212,13 @@ It is unspecified whether `D::param_type` is declared as a (nested)
207
  `class` or via a `typedef`. In this subclause [[rand]], declarations of
208
  `D::param_type` are in the form of `typedef`s for convenience of
209
  exposition only.
210
 
211
  `P` shall satisfy the requirements of `CopyConstructible` (Table 
212
- [[copyconstructible]]), `CopyAssignable` (Table  [[copyassignable]]),
213
- and `EqualityComparable` (Table  [[equalitycomparable]]) types.
 
214
 
215
  For each of the constructors of `D` taking arguments corresponding to
216
  parameters of the distribution, `P` shall have a corresponding
217
  constructor subject to the same requirements and taking arguments
218
  identical in number, type, and default values. Moreover, for each of the
@@ -221,20 +227,19 @@ of the distribution, `P` shall have a corresponding member function with
221
  the identical name, type, and semantics.
222
 
223
  `P` shall have a declaration of the form
224
 
225
  ``` cpp
226
- typedef D distribution_type;
227
  ```
228
 
229
  ### Header `<random>` synopsis <a id="rand.synopsis">[[rand.synopsis]]</a>
230
 
231
  ``` cpp
232
  #include <initializer_list>
233
 
234
  namespace std {
235
-
236
  // [rand.eng.lcong], class template linear_congruential_engine
237
  template<class UIntType, UIntType a, UIntType c, UIntType m>
238
  class linear_congruential_engine;
239
 
240
  // [rand.eng.mers], class template mersenne_twister_engine
@@ -259,30 +264,31 @@ namespace std {
259
  // [rand.adapt.shuf], class template shuffle_order_engine
260
  template<class Engine, size_t k>
261
  class shuffle_order_engine;
262
 
263
  // [rand.predef], engines and engine adaptors with predefined parameters
264
- typedef see below minstd_rand0;
265
- typedef see below minstd_rand;
266
- typedef see below mt19937;
267
- typedef see below mt19937_64;
268
- typedef see below ranlux24_base;
269
- typedef see below ranlux48_base;
270
- typedef see below ranlux24;
271
- typedef see below ranlux48;
272
- typedef see below knuth_b;
273
- typedef see below default_random_engine;
 
274
 
275
  // [rand.device], class random_device
276
  class random_device;
277
 
278
  // [rand.util.seedseq], class seed_seq
279
  class seed_seq;
280
 
281
  // [rand.util.canonical], function template generate_canonical
282
- template<class RealType, size_t bits, class URNG>
283
- RealType generate_canonical(URNG& g);
284
 
285
  // [rand.dist.uni.int], class template uniform_int_distribution
286
  template<class IntType = int>
287
  class uniform_int_distribution;
288
 
@@ -358,12 +364,11 @@ namespace std {
358
  class piecewise_constant_distribution;
359
 
360
  // [rand.dist.samp.plinear], class template piecewise_linear_distribution
361
  template<class RealType = double>
362
  class piecewise_linear_distribution;
363
-
364
- } // namespace std
365
  ```
366
 
367
  ### Random number engine class templates <a id="rand.eng">[[rand.eng]]</a>
368
 
369
  Each type instantiated from a class template specified in this section 
@@ -374,25 +379,30 @@ Except where specified otherwise, the complexity of each function
374
  specified in this section  [[rand.eng]] is constant.
375
 
376
  Except where specified otherwise, no function described in this section 
377
  [[rand.eng]] throws an exception.
378
 
 
 
 
 
 
379
  Descriptions are provided in this section  [[rand.eng]] only for engine
380
- operations that are not described in [[rand.req.eng]] or for
381
- operations where there is additional semantic information. In
382
- particular, declarations for copy constructors, for copy assignment
383
- operators, for streaming operators, and for equality and inequality
384
- operators are not shown in the synopses.
385
 
386
  Each template specified in this section  [[rand.eng]] requires one or
387
  more relationships, involving the value(s) of its non-type template
388
  parameter(s), to hold. A program instantiating any of these templates is
389
  ill-formed if any such required relationship fails to hold.
390
 
391
  For every random number engine and for every random number engine
392
- adaptor `X` defined in this sub-clause ([[rand.eng]]) and in
393
- sub-clause  [[rand.adapt]]:
394
 
395
  - if the constructor
396
  ``` cpp
397
  template <class Sseq> explicit X(Sseq& q);
398
  ```
@@ -421,15 +431,14 @@ algorithm is a modular linear function of the form
421
  TA(xᵢ) = (a ⋅ xᵢ + c) mod m; the generation algorithm is
422
  GA(xᵢ) = xᵢ₊₁.
423
 
424
  ``` cpp
425
  template<class UIntType, UIntType a, UIntType c, UIntType m>
426
- class linear_congruential_engine
427
- {
428
  public:
429
  // types
430
- typedef UIntType result_type;
431
 
432
  // engine characteristics
433
  static constexpr result_type multiplier = a;
434
  static constexpr result_type increment = c;
435
  static constexpr result_type modulus = m;
@@ -449,11 +458,14 @@ public:
449
  };
450
  ```
451
 
452
  If the template parameter `m` is 0, the modulus m used throughout this
453
  section  [[rand.eng.lcong]] is `numeric_limits<result_type>::max()` plus
454
- 1. m need not be representable as a value of type `result_type`.
 
 
 
455
 
456
  If the template parameter `m` is not 0, the following relations shall
457
  hold: `a < m` and `c < m`.
458
 
459
  The textual representation consists of the value of xᵢ.
@@ -488,11 +500,11 @@ sequence X of n values of the type delivered by `x`; all subscripts
488
  applied to X are to be taken modulo n.
489
 
490
  The transition algorithm employs a twisted generalized feedback shift
491
  register defined by shift values n and m, a twist value r, and a
492
  conditional xor-mask a. To improve the uniformity of the result, the
493
- bits of the raw shift register are additionally *tempered* (*i.e.*,
494
  scrambled) according to a bit-scrambling matrix defined by values
495
  u, d, s, b, t, c, and ℓ.
496
 
497
  The state transition is performed as follows:
498
 
@@ -505,15 +517,14 @@ z₁, z₂, z₃, z₄ as follows, then delivers z₄ as its result:
505
  ``` cpp
506
  template<class UIntType, size_t w, size_t n, size_t m, size_t r,
507
  UIntType a, size_t u, UIntType d, size_t s,
508
  UIntType b, size_t t,
509
  UIntType c, size_t l, UIntType f>
510
- class mersenne_twister_engine
511
- {
512
  public:
513
  // types
514
- typedef UIntType result_type;
515
 
516
  // engine characteristics
517
  static constexpr size_t word_size = w;
518
  static constexpr size_t state_size = n;
519
  static constexpr size_t shift_size = m;
@@ -590,24 +601,23 @@ all subscripts applied to X are to be taken modulo r. The state xᵢ
590
  additionally consists of an integer c (known as the *carry*) whose value
591
  is either 0 or 1.
592
 
593
  The state transition is performed as follows:
594
 
595
- This algorithm corresponds to a modular linear function of the form
596
- TA(xᵢ) = (a ⋅ xᵢ) mod b, where b is of the form mʳ - mˢ + 1 and
597
- a = b - (b-1) / m.
598
 
599
  The generation algorithm is given by GA(xᵢ) = y, where y is the value
600
  produced as a result of advancing the engine’s state as described above.
601
 
602
  ``` cpp
603
  template<class UIntType, size_t w, size_t s, size_t r>
604
- class subtract_with_carry_engine
605
- {
606
  public:
607
  // types
608
- typedef UIntType result_type;
609
 
610
  // engine characteristics
611
  static constexpr size_t word_size = w;
612
  static constexpr size_t short_lag = s;
613
  static constexpr size_t long_lag = r;
@@ -669,19 +679,24 @@ X₋₁ is then 0, sets c to 1; otherwise sets c to 0.
669
  ### Random number engine adaptor class templates <a id="rand.adapt">[[rand.adapt]]</a>
670
 
671
  #### In general <a id="rand.adapt.general">[[rand.adapt.general]]</a>
672
 
673
  Each type instantiated from a class template specified in this section 
674
- [[rand.eng]] satisfies the requirements of a random number engine
675
  adaptor ([[rand.req.adapt]]) type.
676
 
677
  Except where specified otherwise, the complexity of each function
678
  specified in this section  [[rand.adapt]] is constant.
679
 
680
  Except where specified otherwise, no function described in this section 
681
  [[rand.adapt]] throws an exception.
682
 
 
 
 
 
 
683
  Descriptions are provided in this section  [[rand.adapt]] only for
684
  adaptor operations that are not described in section  [[rand.req.adapt]]
685
  or for operations where there is additional semantic information. In
686
  particular, declarations for copy constructors, for copy assignment
687
  operators, for streaming operators, and for equality and inequality
@@ -709,15 +724,14 @@ state eⱼ to eⱼ₊₁.
709
  The generation algorithm yields the value returned by the last
710
  invocation of `e()` while advancing `e`’s state as described above.
711
 
712
  ``` cpp
713
  template<class Engine, size_t p, size_t r>
714
- class discard_block_engine
715
- {
716
  public:
717
  // types
718
- typedef typename Engine::result_type result_type;
719
 
720
  // engine characteristics
721
  static constexpr size_t block_size = p;
722
  static constexpr size_t used_block = r;
723
  static constexpr result_type min() { return Engine::min(); }
@@ -764,11 +778,12 @@ state eᵢ of its base engine `e`; the size of the state is the size of
764
  e’s state.
765
 
766
  The transition and generation algorithms are described in terms of the
767
  following integral constants:
768
 
769
- The relation w = n₀ w₀ + (n - n₀)(w₀ + 1) always holds.
 
770
 
771
  The transition algorithm is carried out by invoking `e()` as often as
772
  needed to obtain n₀ values less than y₀ + `e.min()` and n - n₀ values
773
  less than y₁ + `e.min()` .
774
 
@@ -788,15 +803,14 @@ for (k = n₀; k \neq n; k += 1) {
788
  }
789
  ```
790
 
791
  ``` cpp
792
  template<class Engine, size_t w, class UIntType>
793
- class independent_bits_engine
794
- {
795
  public:
796
  // types
797
- typedef UIntType result_type;
798
 
799
  // engine characteristics
800
  static constexpr result_type min() { return 0; }
801
  static constexpr result_type max() { return 2^w - 1; }
802
 
@@ -844,15 +858,14 @@ transition is performed as follows:
844
  The generation algorithm yields the last value of `Y` produced while
845
  advancing `e`’s state as described above.
846
 
847
  ``` cpp
848
  template<class Engine, size_t k>
849
- class shuffle_order_engine
850
- {
851
  public:
852
  // types
853
- typedef typename Engine::result_type result_type;
854
 
855
  // engine characteristics
856
  static constexpr size_t table_size = k;
857
  static constexpr result_type min() { return Engine::min(); }
858
  static constexpr result_type max() { return Engine::max(); }
@@ -874,12 +887,12 @@ public:
874
  // property functions
875
  const Engine& base() const noexcept { return e; };
876
 
877
  private:
878
  Engine e; // exposition only
879
- result_type Y; // exposition only
880
  result_type V[k]; // exposition only
 
881
  };
882
  ```
883
 
884
  The following relation shall hold: `0 < k`.
885
 
@@ -892,124 +905,121 @@ each constructor that is not a copy constructor initializes
892
  successive invocations of `e()`.
893
 
894
  ### Engines and engine adaptors with predefined parameters <a id="rand.predef">[[rand.predef]]</a>
895
 
896
  ``` cpp
897
- typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
898
- minstd_rand0;
899
  ```
900
 
901
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
902
  default-constructed object of type `minstd_rand0` shall produce the
903
  value 1043618065.
904
 
905
  ``` cpp
906
- typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
907
- minstd_rand;
908
  ```
909
 
910
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
911
  default-constructed object of type `minstd_rand` shall produce the value
912
  399268537.
913
 
914
  ``` cpp
915
- typedef mersenne_twister_engine<uint_fast32_t,
916
- 32,624,397,31,0x9908b0df,11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253>
917
- mt19937;
918
  ```
919
 
920
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
921
  default-constructed object of type `mt19937` shall produce the value
922
  4123659995.
923
 
924
  ``` cpp
925
- typedef mersenne_twister_engine<uint_fast64_t,
 
926
  64,312,156,31,0xb5026f5aa96619e9,29,
927
  0x5555555555555555,17,
928
  0x71d67fffeda60000,37,
929
  0xfff7eee000000000,43,
930
- 6364136223846793005>
931
- mt19937_64;
932
  ```
933
 
934
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
935
  default-constructed object of type `mt19937_64` shall produce the value
936
  9981545732273789042.
937
 
938
  ``` cpp
939
- typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
940
- ranlux24_base;
941
  ```
942
 
943
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
944
  default-constructed object of type `ranlux24_base` shall produce the
945
  value 7937952.
946
 
947
  ``` cpp
948
- typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
949
- ranlux48_base;
950
  ```
951
 
952
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
953
  default-constructed object of type `ranlux48_base` shall produce the
954
  value 61839128582725.
955
 
956
  ``` cpp
957
- typedef discard_block_engine<ranlux24_base, 223, 23>
958
- ranlux24;
959
  ```
960
 
961
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
962
  default-constructed object of type `ranlux24` shall produce the value
963
  9901578.
964
 
965
  ``` cpp
966
- typedef discard_block_engine<ranlux48_base, 389, 11>
967
- ranlux48;
968
  ```
969
 
970
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
971
  default-constructed object of type `ranlux48` shall produce the value
972
  249142670248501.
973
 
974
  ``` cpp
975
- typedef shuffle_order_engine<minstd_rand0,256>
976
- knuth_b;
977
  ```
978
 
979
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
980
  default-constructed object of type `knuth_b` shall produce the value
981
  1112339016.
982
 
983
  ``` cpp
984
- typedef implementation-defined
985
- default_random_engine;
986
  ```
987
 
988
- The choice of engine type named by this `typedef` is
989
- implementation-defined. The implementation may select this type on the
990
- basis of performance, size, quality, or any combination of such factors,
991
- so as to provide at least acceptable engine behavior for relatively
992
- casual, inexpert, and/or lightweight use. Because different
993
- implementations may select different underlying engine types, code that
994
- uses this `typedef` need not generate identical sequences across
995
- implementations.
 
 
996
 
997
  ### Class `random_device` <a id="rand.device">[[rand.device]]</a>
998
 
999
- A `random_device` uniform random number generator produces
1000
- non-deterministic random numbers.
1001
 
1002
- If implementation limitations prevent generating non-deterministic
1003
- random numbers, the implementation may employ a random number engine.
1004
 
1005
  ``` cpp
1006
- class random_device
1007
- {
1008
  public:
1009
  // types
1010
- typedef unsigned int result_type;
1011
 
1012
  // generator characteristics
1013
  static constexpr result_type min() { return numeric_limits<result_type>::min(); }
1014
  static constexpr result_type max() { return numeric_limits<result_type>::max(); }
1015
 
@@ -1030,15 +1040,15 @@ public:
1030
 
1031
  ``` cpp
1032
  explicit random_device(const string& token = implementation-defined);
1033
  ```
1034
 
1035
- *Effects:* Constructs a `random_device` non-deterministic uniform random
1036
- number generator object. The semantics and default value of the `token`
1037
- parameter are implementation-defined.[^3]
1038
 
1039
- *Throws:* A value of an implementation-defined type derived from
1040
  `exception` if the `random_device` could not be initialized.
1041
 
1042
  ``` cpp
1043
  double entropy() const noexcept;
1044
  ```
@@ -1049,27 +1059,26 @@ returned by `operator()`, in the range `min()` to log₂( `max()`+1).
1049
 
1050
  ``` cpp
1051
  result_type operator()();
1052
  ```
1053
 
1054
- *Returns:* A non-deterministic random value, uniformly distributed
1055
- between `min()` and `max()`, inclusive. It is implementation-defined how
1056
- these values are generated.
1057
 
1058
- *Throws:* A value of an implementation-defined type derived from
1059
  `exception` if a random number could not be obtained.
1060
 
1061
  ### Utilities <a id="rand.util">[[rand.util]]</a>
1062
 
1063
  #### Class `seed_seq` <a id="rand.util.seedseq">[[rand.util.seedseq]]</a>
1064
 
1065
  ``` cpp
1066
- class seed_seq
1067
- {
1068
  public:
1069
  // types
1070
- typedef uint_least32_t result_type;
1071
 
1072
  // constructors
1073
  seed_seq();
1074
  template<class T>
1075
  seed_seq(initializer_list<T> il);
@@ -1079,11 +1088,11 @@ public:
1079
  // generating functions
1080
  template<class RandomAccessIterator>
1081
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
1082
 
1083
  // property functions
1084
- size_t size() const;
1085
  template<class OutputIterator>
1086
  void param(OutputIterator dest) const;
1087
 
1088
  // no copy functions
1089
  seed_seq(const seed_seq& ) = delete;
@@ -1133,12 +1142,11 @@ for( InputIterator s = begin; s != end; ++s)
1133
  template<class RandomAccessIterator>
1134
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
1135
  ```
1136
 
1137
  *Requires:* `RandomAccessIterator` shall meet the requirements of a
1138
- mutable random access iterator
1139
- (Table  [[tab:iterator.random.access.requirements]]) type. Moreover,
1140
  `iterator_traits<RandomAccessIterator>::value_type` shall denote an
1141
  unsigned integer type capable of accommodating 32-bit quantities.
1142
 
1143
  *Effects:* Does nothing if `begin == end`. Otherwise, with
1144
  s = `v.size()` and n = `end` - `begin`, fills the supplied range
@@ -1149,29 +1157,26 @@ $x \, \xor \, (x \, \rightshift \, 27)$:
1149
 
1150
  *Throws:* What and when `RandomAccessIterator` operations of `begin` and
1151
  `end` throw.
1152
 
1153
  ``` cpp
1154
- size_t size() const;
1155
  ```
1156
 
1157
  *Returns:* The number of 32-bit units that would be returned by a call
1158
  to `param()`.
1159
 
1160
- *Throws:* Nothing.
1161
-
1162
  *Complexity:* Constant time.
1163
 
1164
  ``` cpp
1165
  template<class OutputIterator>
1166
  void param(OutputIterator dest) const;
1167
  ```
1168
 
1169
  *Requires:* `OutputIterator` shall satisfy the requirements of an output
1170
- iterator (Table  [[tab:iterator.output.requirements]]) type. Moreover,
1171
- the expression `*dest = rt` shall be valid for a value `rt` of type
1172
- `result_type`.
1173
 
1174
  *Effects:* Copies the sequence of prepared 32-bit units to the given
1175
  destination, as if by executing the following statement:
1176
 
1177
  ``` cpp
@@ -1182,22 +1187,23 @@ copy(v.begin(), v.end(), dest);
1182
 
1183
  #### Function template `generate_canonical` <a id="rand.util.canonical">[[rand.util.canonical]]</a>
1184
 
1185
  Each function instantiated from the template described in this section 
1186
  [[rand.util.canonical]] maps the result of one or more invocations of a
1187
- supplied uniform random number generator `g` to one member of the
1188
- specified `RealType` such that, if the values gᵢ produced by `g` are
1189
- uniformly distributed, the instantiation’s results tⱼ, 0 ≤ tⱼ < 1, are
1190
- distributed as uniformly as possible as specified below.
1191
 
1192
- Obtaining a value in this way can be a useful step in the process of
1193
- transforming a value generated by a uniform random number generator into
1194
- a value that can be delivered by a random number distribution.
 
1195
 
1196
  ``` cpp
1197
- template<class RealType, size_t bits, class URNG>
1198
- RealType generate_canonical(URNG& g);
1199
  ```
1200
 
1201
  *Complexity:* Exactly k = max(1, ⌈ b / log₂ R ⌉) invocations of `g`,
1202
  where b[^5] is the lesser of `numeric_limits<RealType>::digits` and
1203
  `bits`, and R is the value of `g.max()` - `g.min()` + 1.
@@ -1225,11 +1231,11 @@ for operations where there is additional semantic information. In
1225
  particular, declarations for copy constructors, for copy assignment
1226
  operators, for streaming operators, and for equality and inequality
1227
  operators are not shown in the synopses.
1228
 
1229
  The algorithms for producing each of the specified distributions are
1230
- implementation-defined.
1231
 
1232
  The value of each probability density function p(z) and of each discrete
1233
  probability function P(zᵢ) specified in this section is 0 everywhere
1234
  outside its stated domain.
1235
 
@@ -1243,27 +1249,26 @@ probability function $$%
1243
  P(i\,|\,a,b) = 1 / (b - a + 1)
1244
  \; \mbox{.}$$
1245
 
1246
  ``` cpp
1247
  template<class IntType = int>
1248
- class uniform_int_distribution
1249
- {
1250
  public:
1251
  // types
1252
- typedef IntType result_type;
1253
- typedef unspecified param_type;
1254
 
1255
  // constructors and reset functions
1256
  explicit uniform_int_distribution(IntType a = 0, IntType b = numeric_limits<IntType>::max());
1257
  explicit uniform_int_distribution(const param_type& parm);
1258
  void reset();
1259
 
1260
  // generating functions
1261
- template<class URNG>
1262
- result_type operator()(URNG& g);
1263
- template<class URNG>
1264
- result_type operator()(URNG& g, const param_type& parm);
1265
 
1266
  // property functions
1267
  result_type a() const;
1268
  result_type b() const;
1269
  param_type param() const;
@@ -1302,29 +1307,31 @@ A `uniform_real_distribution` random number distribution produces random
1302
  numbers x, a ≤ x < b, distributed according to the constant probability
1303
  density function $$%
1304
  p(x\,|\,a,b) = 1 / (b - a)
1305
  \; \mbox{.}$$
1306
 
 
 
 
1307
  ``` cpp
1308
  template<class RealType = double>
1309
- class uniform_real_distribution
1310
- {
1311
  public:
1312
  // types
1313
- typedef RealType result_type;
1314
- typedef unspecified param_type;
1315
 
1316
  // constructors and reset functions
1317
  explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
1318
  explicit uniform_real_distribution(const param_type& parm);
1319
  void reset();
1320
 
1321
  // generating functions
1322
- template<class URNG>
1323
- result_type operator()(URNG& g);
1324
- template<class URNG>
1325
- result_type operator()(URNG& g, const param_type& parm);
1326
 
1327
  // property functions
1328
  result_type a() const;
1329
  result_type b() const;
1330
  param_type param() const;
@@ -1369,27 +1376,26 @@ values b distributed according to the discrete probability function $$%
1369
  1-p & \mbox{if} & b = \tcode{false}
1370
  \end{array}\right.
1371
  \; \mbox{.}$$
1372
 
1373
  ``` cpp
1374
- class bernoulli_distribution
1375
- {
1376
  public:
1377
  // types
1378
- typedef bool result_type;
1379
- typedef unspecified param_type;
1380
 
1381
  // constructors and reset functions
1382
  explicit bernoulli_distribution(double p = 0.5);
1383
  explicit bernoulli_distribution(const param_type& parm);
1384
  void reset();
1385
 
1386
  // generating functions
1387
- template<class URNG>
1388
- result_type operator()(URNG& g);
1389
- template<class URNG>
1390
- result_type operator()(URNG& g, const param_type& parm);
1391
 
1392
  // property functions
1393
  double p() const;
1394
  param_type param() const;
1395
  void param(const param_type& parm);
@@ -1423,27 +1429,26 @@ $$%
1423
  = \binom{t}{i} \cdot p^i \cdot (1-p)^{t-i}
1424
  \; \mbox{.}$$
1425
 
1426
  ``` cpp
1427
  template<class IntType = int>
1428
- class binomial_distribution
1429
- {
1430
  public:
1431
  // types
1432
- typedef IntType result_type;
1433
- typedef unspecified param_type;
1434
 
1435
  // constructors and reset functions
1436
  explicit binomial_distribution(IntType t = 1, double p = 0.5);
1437
  explicit binomial_distribution(const param_type& parm);
1438
  void reset();
1439
 
1440
  // generating functions
1441
- template<class URNG>
1442
- result_type operator()(URNG& g);
1443
- template<class URNG>
1444
- result_type operator()(URNG& g, const param_type& parm);
1445
 
1446
  // property functions
1447
  IntType t() const;
1448
  double p() const;
1449
  param_type param() const;
@@ -1485,27 +1490,26 @@ $$%
1485
  = p \cdot (1-p)^{i}
1486
  \; \mbox{.}$$
1487
 
1488
  ``` cpp
1489
  template<class IntType = int>
1490
- class geometric_distribution
1491
- {
1492
  public:
1493
  // types
1494
- typedef IntType result_type;
1495
- typedef unspecified param_type;
1496
 
1497
  // constructors and reset functions
1498
  explicit geometric_distribution(double p = 0.5);
1499
  explicit geometric_distribution(const param_type& parm);
1500
  void reset();
1501
 
1502
  // generating functions
1503
- template<class URNG>
1504
- result_type operator()(URNG& g);
1505
- template<class URNG>
1506
- result_type operator()(URNG& g, const param_type& parm);
1507
 
1508
  // property functions
1509
  double p() const;
1510
  param_type param() const;
1511
  void param(const param_type& parm);
@@ -1537,29 +1541,31 @@ random integers i ≥ 0 distributed according to the discrete probability
1537
  function $$%
1538
  P(i\,|\,k,p)
1539
  = \binom{k+i-1}{i} \cdot p^k \cdot (1-p)^i
1540
  \; \mbox{.}$$
1541
 
 
 
 
1542
  ``` cpp
1543
  template<class IntType = int>
1544
- class negative_binomial_distribution
1545
- {
1546
  public:
1547
  // types
1548
- typedef IntType result_type;
1549
- typedef unspecified param_type;
1550
 
1551
  // constructor and reset functions
1552
  explicit negative_binomial_distribution(IntType k = 1, double p = 0.5);
1553
  explicit negative_binomial_distribution(const param_type& parm);
1554
  void reset();
1555
 
1556
  // generating functions
1557
- template<class URNG>
1558
- result_type operator()(URNG& g);
1559
- template<class URNG>
1560
- result_type operator()(URNG& g, const param_type& parm);
1561
 
1562
  // property functions
1563
  IntType k() const;
1564
  double p() const;
1565
  param_type param() const;
@@ -1609,23 +1615,23 @@ distribution’s *mean* .
1609
  template<class IntType = int>
1610
  class poisson_distribution
1611
  {
1612
  public:
1613
  // types
1614
- typedef IntType result_type;
1615
- typedef unspecified param_type;
1616
 
1617
  // constructors and reset functions
1618
  explicit poisson_distribution(double mean = 1.0);
1619
  explicit poisson_distribution(const param_type& parm);
1620
  void reset();
1621
 
1622
  // generating functions
1623
- template<class URNG>
1624
- result_type operator()(URNG& g);
1625
- template<class URNG>
1626
- result_type operator()(URNG& g, const param_type& parm);
1627
 
1628
  // property functions
1629
  double mean() const;
1630
  param_type param() const;
1631
  void param(const param_type& parm);
@@ -1659,27 +1665,26 @@ $$%
1659
  = \lambda e^{-\lambda x}
1660
  \; \mbox{.}$$
1661
 
1662
  ``` cpp
1663
  template<class RealType = double>
1664
- class exponential_distribution
1665
- {
1666
  public:
1667
  // types
1668
- typedef RealType result_type;
1669
- typedef unspecified param_type;
1670
 
1671
  // constructors and reset functions
1672
  explicit exponential_distribution(RealType lambda = 1.0);
1673
  explicit exponential_distribution(const param_type& parm);
1674
  void reset();
1675
 
1676
  // generating functions
1677
- template<class URNG>
1678
- result_type operator()(URNG& g);
1679
- template<class URNG>
1680
- result_type operator()(URNG& g, const param_type& parm);
1681
 
1682
  // property functions
1683
  RealType lambda() const;
1684
  param_type param() const;
1685
  void param(const param_type& parm);
@@ -1692,11 +1697,11 @@ public:
1692
  explicit exponential_distribution(RealType lambda = 1.0);
1693
  ```
1694
 
1695
  *Requires:* 0 < `lambda`.
1696
 
1697
- *Effects:* Constructs a `exponential_distribution` object; `lambda`
1698
  corresponds to the parameter of the distribution.
1699
 
1700
  ``` cpp
1701
  RealType lambda() const;
1702
  ```
@@ -1714,27 +1719,26 @@ $$%
1714
  \, \cdot \, x^{\, \alpha-1}
1715
  \; \mbox{.}$$
1716
 
1717
  ``` cpp
1718
  template<class RealType = double>
1719
- class gamma_distribution
1720
- {
1721
  public:
1722
  // types
1723
- typedef RealType result_type;
1724
- typedef unspecified param_type;
1725
 
1726
  // constructors and reset functions
1727
  explicit gamma_distribution(RealType alpha = 1.0, RealType beta = 1.0);
1728
  explicit gamma_distribution(const param_type& parm);
1729
  void reset();
1730
 
1731
  // generating functions
1732
- template<class URNG>
1733
- result_type operator()(URNG& g);
1734
- template<class URNG>
1735
- result_type operator()(URNG& g, const param_type& parm);
1736
 
1737
  // property functions
1738
  RealType alpha() const;
1739
  RealType beta() const;
1740
  param_type param() const;
@@ -1778,27 +1782,26 @@ $$%
1778
  \cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
1779
  \; \mbox{.}$$
1780
 
1781
  ``` cpp
1782
  template<class RealType = double>
1783
- class weibull_distribution
1784
- {
1785
  public:
1786
  // types
1787
- typedef RealType result_type;
1788
- typedef unspecified param_type;
1789
 
1790
  // constructor and reset functions
1791
  explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0);
1792
  explicit weibull_distribution(const param_type& parm);
1793
  void reset();
1794
 
1795
  // generating functions
1796
- template<class URNG>
1797
- result_type operator()(URNG& g);
1798
- template<class URNG>
1799
- result_type operator()(URNG& g, const param_type& parm);
1800
 
1801
  // property functions
1802
  RealType a() const;
1803
  RealType b() const;
1804
  param_type param() const;
@@ -1843,27 +1846,26 @@ function[^6] $$%
1843
  \right)
1844
  \; \mbox{.}$$
1845
 
1846
  ``` cpp
1847
  template<class RealType = double>
1848
- class extreme_value_distribution
1849
- {
1850
  public:
1851
  // types
1852
- typedef RealType result_type;
1853
- typedef unspecified param_type;
1854
 
1855
  // constructor and reset functions
1856
  explicit extreme_value_distribution(RealType a = 0.0, RealType b = 1.0);
1857
  explicit extreme_value_distribution(const param_type& parm);
1858
  void reset();
1859
 
1860
  // generating functions
1861
- template<class URNG>
1862
- result_type operator()(URNG& g);
1863
- template<class URNG>
1864
- result_type operator()(URNG& g, const param_type& parm);
1865
 
1866
  // property functions
1867
  RealType a() const;
1868
  RealType b() const;
1869
  param_type param() const;
@@ -1913,27 +1915,26 @@ numbers x distributed according to the probability density function $$%
1913
  \; \mbox{.}$$ The distribution parameters μ and σ are also known as this
1914
  distribution’s *mean* and *standard deviation* .
1915
 
1916
  ``` cpp
1917
  template<class RealType = double>
1918
- class normal_distribution
1919
- {
1920
  public:
1921
  // types
1922
- typedef RealType result_type;
1923
- typedef unspecified param_type;
1924
 
1925
  // constructors and reset functions
1926
  explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0);
1927
  explicit normal_distribution(const param_type& parm);
1928
  void reset();
1929
 
1930
  // generating functions
1931
- template<class URNG>
1932
- result_type operator()(URNG& g);
1933
- template<class URNG>
1934
- result_type operator()(URNG& g, const param_type& parm);
1935
 
1936
  // property functions
1937
  RealType mean() const;
1938
  RealType stddev() const;
1939
  param_type param() const;
@@ -1981,27 +1982,26 @@ $$%
1981
  }
1982
  \; \mbox{.}$$
1983
 
1984
  ``` cpp
1985
  template<class RealType = double>
1986
- class lognormal_distribution
1987
- {
1988
  public:
1989
  // types
1990
- typedef RealType result_type;
1991
- typedef unspecified param_type;
1992
 
1993
  // constructor and reset functions
1994
  explicit lognormal_distribution(RealType m = 0.0, RealType s = 1.0);
1995
  explicit lognormal_distribution(const param_type& parm);
1996
  void reset();
1997
 
1998
  // generating functions
1999
- template<class URNG>
2000
- result_type operator()(URNG& g);
2001
- template<class URNG>
2002
- result_type operator()(URNG& g, const param_type& parm);
2003
 
2004
  // property functions
2005
  RealType m() const;
2006
  RealType s() const;
2007
  param_type param() const;
@@ -2044,27 +2044,26 @@ $$%
2044
  {\Gamma(n/2) \cdot 2^{n/2}}
2045
  \; \mbox{.}$$
2046
 
2047
  ``` cpp
2048
  template<class RealType = double>
2049
- class chi_squared_distribution
2050
- {
2051
  public:
2052
  // types
2053
- typedef RealType result_type;
2054
- typedef unspecified param_type;
2055
 
2056
  // constructor and reset functions
2057
  explicit chi_squared_distribution(RealType n = 1);
2058
  explicit chi_squared_distribution(const param_type& parm);
2059
  void reset();
2060
 
2061
  // generating functions
2062
- template<class URNG>
2063
- result_type operator()(URNG& g);
2064
- template<class URNG>
2065
- result_type operator()(URNG& g, const param_type& parm);
2066
 
2067
  // property functions
2068
  RealType n() const;
2069
  param_type param() const;
2070
  void param(const param_type& parm);
@@ -2097,27 +2096,26 @@ numbers x distributed according to the probability density function $$%
2097
  = \left( \pi b \left( 1 + \left( \frac{x-a}{b} \right)^2 \;\right)\right)^{-1}
2098
  \; \mbox{.}$$
2099
 
2100
  ``` cpp
2101
  template<class RealType = double>
2102
- class cauchy_distribution
2103
- {
2104
  public:
2105
  // types
2106
- typedef RealType result_type;
2107
- typedef unspecified param_type;
2108
 
2109
  // constructor and reset functions
2110
  explicit cauchy_distribution(RealType a = 0.0, RealType b = 1.0);
2111
  explicit cauchy_distribution(const param_type& parm);
2112
  void reset();
2113
 
2114
  // generating functions
2115
- template<class URNG>
2116
- result_type operator()(URNG& g);
2117
- template<class URNG>
2118
- result_type operator()(URNG& g, const param_type& parm);
2119
 
2120
  // property functions
2121
  RealType a() const;
2122
  RealType b() const;
2123
  param_type param() const;
@@ -2166,27 +2164,26 @@ $$%
2166
  {\left( 1 + \frac{m x}{n} \right)}^{-(m+n)/2}
2167
  \; \mbox{.}$$
2168
 
2169
  ``` cpp
2170
  template<class RealType = double>
2171
- class fisher_f_distribution
2172
- {
2173
  public:
2174
  // types
2175
- typedef RealType result_type;
2176
- typedef unspecified param_type;
2177
 
2178
  // constructor and reset functions
2179
  explicit fisher_f_distribution(RealType m = 1, RealType n = 1);
2180
  explicit fisher_f_distribution(const param_type& parm);
2181
  void reset();
2182
 
2183
  // generating functions
2184
- template<class URNG>
2185
- result_type operator()(URNG& g);
2186
- template<class URNG>
2187
- result_type operator()(URNG& g, const param_type& parm);
2188
 
2189
  // property functions
2190
  RealType m() const;
2191
  RealType n() const;
2192
  param_type param() const;
@@ -2231,27 +2228,26 @@ numbers x distributed according to the probability density function $$%
2231
  \cdot \left( 1+\frac{x^2}{n} \right) ^ {-(n+1)/2}
2232
  \; \mbox{.}$$
2233
 
2234
  ``` cpp
2235
  template<class RealType = double>
2236
- class student_t_distribution
2237
- {
2238
  public:
2239
  // types
2240
- typedef RealType result_type;
2241
- typedef unspecified param_type;
2242
 
2243
  // constructor and reset functions
2244
  explicit student_t_distribution(RealType n = 1);
2245
  explicit student_t_distribution(const param_type& parm);
2246
  void reset();
2247
 
2248
  // generating functions
2249
- template<class URNG>
2250
- result_type operator()(URNG& g);
2251
- template<class URNG>
2252
- result_type operator()(URNG& g, const param_type& parm);
2253
 
2254
  // property functions
2255
  RealType n() const;
2256
  param_type param() const;
2257
  void param(const param_type& parm);
@@ -2293,16 +2289,15 @@ the values wₖ, commonly known as the *weights* , shall be non-negative,
2293
  non-NaN, and non-infinity. Moreover, the following relation shall hold:
2294
  0 < S = w₀ + ⋯ + wₙ₋₁.
2295
 
2296
  ``` cpp
2297
  template<class IntType = int>
2298
- class discrete_distribution
2299
- {
2300
  public:
2301
  // types
2302
- typedef IntType result_type;
2303
- typedef unspecified param_type;
2304
 
2305
  // constructor and reset functions
2306
  discrete_distribution();
2307
  template<class InputIterator>
2308
  discrete_distribution(InputIterator firstW, InputIterator lastW);
@@ -2311,14 +2306,14 @@ public:
2311
  discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
2312
  explicit discrete_distribution(const param_type& parm);
2313
  void reset();
2314
 
2315
  // generating functions
2316
- template<class URNG>
2317
- result_type operator()(URNG& g);
2318
- template<class URNG>
2319
- result_type operator()(URNG& g, const param_type& parm);
2320
 
2321
  // property functions
2322
  vector<double> probabilities() const;
2323
  param_type param() const;
2324
  void param(const param_type& parm);
@@ -2330,19 +2325,22 @@ public:
2330
  ``` cpp
2331
  discrete_distribution();
2332
  ```
2333
 
2334
  *Effects:* Constructs a `discrete_distribution` object with n = 1 and
2335
- p₀ = 1. Such an object will always deliver the value 0.
 
 
 
2336
 
2337
  ``` cpp
2338
  template<class InputIterator>
2339
  discrete_distribution(InputIterator firstW, InputIterator lastW);
2340
  ```
2341
 
2342
  *Requires:* `InputIterator` shall satisfy the requirements of an input
2343
- iterator (Table  [[tab:iterator.input.requirements]]) type. Moreover,
2344
  `iterator_traits<InputIterator>::value_type` shall denote a type that is
2345
  convertible to `double`. If `firstW == lastW`, let n = 1 and w₀ = 1.
2346
  Otherwise, [`firstW`, `lastW`) shall form a sequence w of length n > 0.
2347
 
2348
  *Effects:* Constructs a `discrete_distribution` object with
@@ -2403,34 +2401,34 @@ commonly known as the *weights* , shall be non-negative, non-NaN, and
2403
  non-infinity. Moreover, the following relation shall hold:
2404
  0 < S = w₀ + ⋯ + wₙ₋₁.
2405
 
2406
  ``` cpp
2407
  template<class RealType = double>
2408
- class piecewise_constant_distribution
2409
- {
2410
  public:
2411
  // types
2412
- typedef RealType result_type;
2413
- typedef unspecified param_type;
2414
 
2415
  // constructor and reset functions
2416
  piecewise_constant_distribution();
2417
  template<class InputIteratorB, class InputIteratorW>
2418
  piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
2419
  InputIteratorW firstW);
2420
  template<class UnaryOperation>
2421
  piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
2422
  template<class UnaryOperation>
2423
- piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
 
2424
  explicit piecewise_constant_distribution(const param_type& parm);
2425
  void reset();
2426
 
2427
  // generating functions
2428
- template<class URNG>
2429
- result_type operator()(URNG& g);
2430
- template<class URNG>
2431
- result_type operator()(URNG& g, const param_type& parm);
2432
 
2433
  // property functions
2434
  vector<result_type> intervals() const;
2435
  vector<result_type> densities() const;
2436
  param_type param() const;
@@ -2543,16 +2541,15 @@ relation shall hold: $$%
2543
  \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k)
2544
  \; \mbox{.}$$
2545
 
2546
  ``` cpp
2547
  template<class RealType = double>
2548
- class piecewise_linear_distribution
2549
- {
2550
  public:
2551
  // types
2552
- typedef RealType result_type;
2553
- typedef unspecified param_type;
2554
 
2555
  // constructor and reset functions
2556
  piecewise_linear_distribution();
2557
  template<class InputIteratorB, class InputIteratorW>
2558
  piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
@@ -2563,14 +2560,14 @@ public:
2563
  piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
2564
  explicit piecewise_linear_distribution(const param_type& parm);
2565
  void reset();
2566
 
2567
  // generating functions
2568
- template<class URNG>
2569
- result_type operator()(URNG& g);
2570
- template<class URNG>
2571
- result_type operator()(URNG& g, const param_type& parm);
2572
 
2573
  // property functions
2574
  vector<result_type> intervals() const;
2575
  vector<result_type> densities() const;
2576
  param_type param() const;
@@ -2656,5 +2653,30 @@ vector<result_type> densities() const;
2656
 
2657
  *Returns:* A `vector<result_type>` whose `size` member returns n and
2658
  whose `operator[]` member returns ρₖ when invoked with argument k for
2659
  k = 0, …, n.
2660
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  This subclause defines a facility for generating (pseudo-)random
4
  numbers.
5
 
6
  In addition to a few utilities, four categories of entities are
7
+ described: *uniform random bit generators*, *random number engines*,
8
  *random number engine adaptors*, and *random number distributions*.
9
  These categorizations are applicable to types that satisfy the
10
  corresponding requirements, to objects instantiated from such types, and
11
+ to templates producing such types when instantiated.
12
+
13
+ [*Note 1*: These entities are specified in such a way as to permit the
14
+ binding of any uniform random bit generator object `e` as the argument
15
+ to any random number distribution object `d`, thus producing a
16
+ zero-argument function object such as given by
17
+ `bind(d,e)`. — *end note*]
18
 
19
  Each of the entities specified via this subclause has an associated
20
  arithmetic type ([[basic.fundamental]]) identified as `result_type`.
21
  With `T` as the `result_type` thus associated with such an entity, that
22
  entity is characterized:
 
38
  template:
39
 
40
  Throughout this subclause [[rand]], phrases of the form “`x` is an
41
  iterator of a specific kind” shall be interpreted as equivalent to the
42
  more formal requirement that “`x` is a value of a type satisfying the
43
+ requirements of the specified iterator type”.
44
 
45
  Throughout this subclause [[rand]], any constructor that can be called
46
  with a single argument and that satisfies a requirement specified in
47
  this subclause shall be declared `explicit`.
48
 
49
  #### Seed sequence requirements <a id="rand.req.seedseq">[[rand.req.seedseq]]</a>
50
 
51
  A *seed sequence* is an object that consumes a sequence of
52
  integer-valued data and produces a requested number of unsigned integer
53
+ values i, 0 ≤ i < 2³², based on the consumed data.
54
+
55
+ [*Note 1*: Such an object provides a mechanism to avoid replication of
56
+ streams of random variates. This can be useful, for example, in
57
+ applications requiring large numbers of random number
58
+ engines. — *end note*]
59
 
60
  A class `S` satisfies the requirements of a seed sequence if the
61
  expressions shown in Table  [[tab:SeedSequence]] are valid and have the
62
  indicated semantics, and if `S` also satisfies all other requirements of
63
  this section [[rand.req.seedseq]]. In that Table and throughout this
64
  section:
65
 
66
+ #### Uniform random bit generator requirements <a id="rand.req.urng">[[rand.req.urng]]</a>
67
 
68
+ A *uniform random bit generator* `g` of type `G` is a function object
69
  returning unsigned integer values such that each value in the range of
70
+ possible results has (ideally) equal probability of being returned.
 
 
71
 
72
+ [*Note 1*: The degree to which `g`’s results approximate the ideal is
73
+ often determined statistically. — *end note*]
74
+
75
+ A class `G` satisfies the requirements of a *uniform random bit
76
  generator* if the expressions shown in Table 
77
+ [[tab:UniformRandomBitGenerator]] are valid and have the indicated
78
  semantics, and if `G` also satisfies all other requirements of this
79
  section [[rand.req.urng]]. In that Table and throughout this section:
80
 
81
  The following relation shall hold: `G::min() < G::max()`.
82
 
83
  #### Random number engine requirements <a id="rand.req.eng">[[rand.req.eng]]</a>
84
 
85
  A *random number engine* (commonly shortened to *engine*) `e` of type
86
+ `E` is a uniform random bit generator that additionally meets the
87
+ requirements (e.g., for seeding and for input/output) specified in this
88
+ section.
89
 
90
  At any given time, `e` has a state eᵢ for some integer i ≥ 0. Upon
91
  construction, `e` has an initial state e₀. An engine’s state may be
92
  established via a constructor, a `seed` function, assignment, or a
93
  suitable `operator>>`.
94
 
95
  `E`’s specification shall define:
96
 
97
+ A class `E` that satisfies the requirements of a uniform random bit
98
  generator ([[rand.req.urng]]) also satisfies the requirements of a
99
  *random number engine* if the expressions shown in Table 
100
  [[tab:RandomEngine]] are valid and have the indicated semantics, and if
101
  `E` also satisfies all other requirements of this section
102
  [[rand.req.eng]]. In that Table and throughout this section:
103
 
104
  where `charT` and `traits` are constrained according to Clause 
105
  [[strings]] and Clause  [[input.output]].
106
 
107
  `E` shall meet the requirements of `CopyConstructible` (Table 
108
+ [[tab:copyconstructible]]) and `CopyAssignable` (Table 
109
+ [[tab:copyassignable]]) types. These operations shall each be of
110
+ complexity no worse than 𝑂(\mbox{size of state}).
111
 
112
  #### Random number engine adaptor requirements <a id="rand.req.adapt">[[rand.req.adapt]]</a>
113
 
114
  A *random number engine adaptor* (commonly shortened to *adaptor*) `a`
115
  of type `A` is a random number engine that takes values produced by some
 
141
  ```
142
 
143
  *Effects:* The base engine is initialized with `s`.
144
 
145
  ``` cpp
146
+ template<class Sseq> A::A(Sseq& q);
147
  ```
148
 
149
  *Effects:* The base engine is initialized with `q`.
150
 
151
  ``` cpp
 
193
 
194
  where `charT` and `traits` are constrained according to Clauses 
195
  [[strings]] and [[input.output]].
196
 
197
  `D` shall satisfy the requirements of `CopyConstructible` (Table 
198
+ [[tab:copyconstructible]]) and `CopyAssignable` (Table 
199
+ [[tab:copyassignable]]) types.
200
 
201
  The sequence of numbers produced by repeated invocations of `d(g)` shall
202
  be independent of any invocation of `os << d` or of any `const` member
203
  function of `D` between any of the invocations `d(g)`.
204
 
 
212
  `class` or via a `typedef`. In this subclause [[rand]], declarations of
213
  `D::param_type` are in the form of `typedef`s for convenience of
214
  exposition only.
215
 
216
  `P` shall satisfy the requirements of `CopyConstructible` (Table 
217
+ [[tab:copyconstructible]]), `CopyAssignable` (Table 
218
+ [[tab:copyassignable]]), and `EqualityComparable` (Table 
219
+ [[tab:equalitycomparable]]) types.
220
 
221
  For each of the constructors of `D` taking arguments corresponding to
222
  parameters of the distribution, `P` shall have a corresponding
223
  constructor subject to the same requirements and taking arguments
224
  identical in number, type, and default values. Moreover, for each of the
 
227
  the identical name, type, and semantics.
228
 
229
  `P` shall have a declaration of the form
230
 
231
  ``` cpp
232
+ using distribution_type = D;
233
  ```
234
 
235
  ### Header `<random>` synopsis <a id="rand.synopsis">[[rand.synopsis]]</a>
236
 
237
  ``` cpp
238
  #include <initializer_list>
239
 
240
  namespace std {
 
241
  // [rand.eng.lcong], class template linear_congruential_engine
242
  template<class UIntType, UIntType a, UIntType c, UIntType m>
243
  class linear_congruential_engine;
244
 
245
  // [rand.eng.mers], class template mersenne_twister_engine
 
264
  // [rand.adapt.shuf], class template shuffle_order_engine
265
  template<class Engine, size_t k>
266
  class shuffle_order_engine;
267
 
268
  // [rand.predef], engines and engine adaptors with predefined parameters
269
+ using minstd_rand0 = see below;
270
+ using minstd_rand = see below;
271
+ using mt19937 = see below;
272
+ using mt19937_64 = see below;
273
+ using ranlux24_base = see below;
274
+ using ranlux48_base = see below;
275
+ using ranlux24 = see below;
276
+ using ranlux48 = see below;
277
+ using knuth_b = see below;
278
+
279
+ using default_random_engine = see below;
280
 
281
  // [rand.device], class random_device
282
  class random_device;
283
 
284
  // [rand.util.seedseq], class seed_seq
285
  class seed_seq;
286
 
287
  // [rand.util.canonical], function template generate_canonical
288
+ template<class RealType, size_t bits, class URBG>
289
+ RealType generate_canonical(URBG& g);
290
 
291
  // [rand.dist.uni.int], class template uniform_int_distribution
292
  template<class IntType = int>
293
  class uniform_int_distribution;
294
 
 
364
  class piecewise_constant_distribution;
365
 
366
  // [rand.dist.samp.plinear], class template piecewise_linear_distribution
367
  template<class RealType = double>
368
  class piecewise_linear_distribution;
369
+ }
 
370
  ```
371
 
372
  ### Random number engine class templates <a id="rand.eng">[[rand.eng]]</a>
373
 
374
  Each type instantiated from a class template specified in this section 
 
379
  specified in this section  [[rand.eng]] is constant.
380
 
381
  Except where specified otherwise, no function described in this section 
382
  [[rand.eng]] throws an exception.
383
 
384
+ Every function described in this section  [[rand.eng]] that has a
385
+ function parameter `q` of type `Sseq&` for a template type parameter
386
+ named `Sseq` that is different from type `seed_seq` throws what and when
387
+ the invocation of `q.generate` throws.
388
+
389
  Descriptions are provided in this section  [[rand.eng]] only for engine
390
+ operations that are not described in [[rand.req.eng]] or for operations
391
+ where there is additional semantic information. In particular,
392
+ declarations for copy constructors, for copy assignment operators, for
393
+ streaming operators, and for equality and inequality operators are not
394
+ shown in the synopses.
395
 
396
  Each template specified in this section  [[rand.eng]] requires one or
397
  more relationships, involving the value(s) of its non-type template
398
  parameter(s), to hold. A program instantiating any of these templates is
399
  ill-formed if any such required relationship fails to hold.
400
 
401
  For every random number engine and for every random number engine
402
+ adaptor `X` defined in this subclause ([[rand.eng]]) and in subclause 
403
+ [[rand.adapt]]:
404
 
405
  - if the constructor
406
  ``` cpp
407
  template <class Sseq> explicit X(Sseq& q);
408
  ```
 
431
  TA(xᵢ) = (a ⋅ xᵢ + c) mod m; the generation algorithm is
432
  GA(xᵢ) = xᵢ₊₁.
433
 
434
  ``` cpp
435
  template<class UIntType, UIntType a, UIntType c, UIntType m>
436
+ class linear_congruential_engine {
 
437
  public:
438
  // types
439
+ using result_type = UIntType;
440
 
441
  // engine characteristics
442
  static constexpr result_type multiplier = a;
443
  static constexpr result_type increment = c;
444
  static constexpr result_type modulus = m;
 
458
  };
459
  ```
460
 
461
  If the template parameter `m` is 0, the modulus m used throughout this
462
  section  [[rand.eng.lcong]] is `numeric_limits<result_type>::max()` plus
463
+ 1.
464
+
465
+ [*Note 1*: m need not be representable as a value of type
466
+ `result_type`. — *end note*]
467
 
468
  If the template parameter `m` is not 0, the following relations shall
469
  hold: `a < m` and `c < m`.
470
 
471
  The textual representation consists of the value of xᵢ.
 
500
  applied to X are to be taken modulo n.
501
 
502
  The transition algorithm employs a twisted generalized feedback shift
503
  register defined by shift values n and m, a twist value r, and a
504
  conditional xor-mask a. To improve the uniformity of the result, the
505
+ bits of the raw shift register are additionally *tempered* (i.e.,
506
  scrambled) according to a bit-scrambling matrix defined by values
507
  u, d, s, b, t, c, and ℓ.
508
 
509
  The state transition is performed as follows:
510
 
 
517
  ``` cpp
518
  template<class UIntType, size_t w, size_t n, size_t m, size_t r,
519
  UIntType a, size_t u, UIntType d, size_t s,
520
  UIntType b, size_t t,
521
  UIntType c, size_t l, UIntType f>
522
+ class mersenne_twister_engine {
 
523
  public:
524
  // types
525
+ using result_type = UIntType;
526
 
527
  // engine characteristics
528
  static constexpr size_t word_size = w;
529
  static constexpr size_t state_size = n;
530
  static constexpr size_t shift_size = m;
 
601
  additionally consists of an integer c (known as the *carry*) whose value
602
  is either 0 or 1.
603
 
604
  The state transition is performed as follows:
605
 
606
+ [*Note 1*: This algorithm corresponds to a modular linear function of
607
+ the form TA(xᵢ) = (a ⋅ xᵢ) mod b, where b is of the form mʳ - mˢ + 1
608
+ and a = b - (b-1) / m. — *end note*]
609
 
610
  The generation algorithm is given by GA(xᵢ) = y, where y is the value
611
  produced as a result of advancing the engine’s state as described above.
612
 
613
  ``` cpp
614
  template<class UIntType, size_t w, size_t s, size_t r>
615
+ class subtract_with_carry_engine {
 
616
  public:
617
  // types
618
+ using result_type = UIntType;
619
 
620
  // engine characteristics
621
  static constexpr size_t word_size = w;
622
  static constexpr size_t short_lag = s;
623
  static constexpr size_t long_lag = r;
 
679
  ### Random number engine adaptor class templates <a id="rand.adapt">[[rand.adapt]]</a>
680
 
681
  #### In general <a id="rand.adapt.general">[[rand.adapt.general]]</a>
682
 
683
  Each type instantiated from a class template specified in this section 
684
+ [[rand.adapt]] satisfies the requirements of a random number engine
685
  adaptor ([[rand.req.adapt]]) type.
686
 
687
  Except where specified otherwise, the complexity of each function
688
  specified in this section  [[rand.adapt]] is constant.
689
 
690
  Except where specified otherwise, no function described in this section 
691
  [[rand.adapt]] throws an exception.
692
 
693
+ Every function described in this section  [[rand.adapt]] that has a
694
+ function parameter `q` of type `Sseq&` for a template type parameter
695
+ named `Sseq` that is different from type `seed_seq` throws what and when
696
+ the invocation of `q.generate` throws.
697
+
698
  Descriptions are provided in this section  [[rand.adapt]] only for
699
  adaptor operations that are not described in section  [[rand.req.adapt]]
700
  or for operations where there is additional semantic information. In
701
  particular, declarations for copy constructors, for copy assignment
702
  operators, for streaming operators, and for equality and inequality
 
724
  The generation algorithm yields the value returned by the last
725
  invocation of `e()` while advancing `e`’s state as described above.
726
 
727
  ``` cpp
728
  template<class Engine, size_t p, size_t r>
729
+ class discard_block_engine {
 
730
  public:
731
  // types
732
+ using result_type = typename Engine::result_type;
733
 
734
  // engine characteristics
735
  static constexpr size_t block_size = p;
736
  static constexpr size_t used_block = r;
737
  static constexpr result_type min() { return Engine::min(); }
 
778
  e’s state.
779
 
780
  The transition and generation algorithms are described in terms of the
781
  following integral constants:
782
 
783
+ [*Note 1*: The relation w = n₀ w₀ + (n - n₀)(w₀ + 1) always
784
+ holds. — *end note*]
785
 
786
  The transition algorithm is carried out by invoking `e()` as often as
787
  needed to obtain n₀ values less than y₀ + `e.min()` and n - n₀ values
788
  less than y₁ + `e.min()` .
789
 
 
803
  }
804
  ```
805
 
806
  ``` cpp
807
  template<class Engine, size_t w, class UIntType>
808
+ class independent_bits_engine {
 
809
  public:
810
  // types
811
+ using result_type = UIntType;
812
 
813
  // engine characteristics
814
  static constexpr result_type min() { return 0; }
815
  static constexpr result_type max() { return 2^w - 1; }
816
 
 
858
  The generation algorithm yields the last value of `Y` produced while
859
  advancing `e`’s state as described above.
860
 
861
  ``` cpp
862
  template<class Engine, size_t k>
863
+ class shuffle_order_engine {
 
864
  public:
865
  // types
866
+ using result_type = typename Engine::result_type;
867
 
868
  // engine characteristics
869
  static constexpr size_t table_size = k;
870
  static constexpr result_type min() { return Engine::min(); }
871
  static constexpr result_type max() { return Engine::max(); }
 
887
  // property functions
888
  const Engine& base() const noexcept { return e; };
889
 
890
  private:
891
  Engine e; // exposition only
 
892
  result_type V[k]; // exposition only
893
+ result_type Y; // exposition only
894
  };
895
  ```
896
 
897
  The following relation shall hold: `0 < k`.
898
 
 
905
  successive invocations of `e()`.
906
 
907
  ### Engines and engine adaptors with predefined parameters <a id="rand.predef">[[rand.predef]]</a>
908
 
909
  ``` cpp
910
+ using minstd_rand0 =
911
+ linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>;
912
  ```
913
 
914
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
915
  default-constructed object of type `minstd_rand0` shall produce the
916
  value 1043618065.
917
 
918
  ``` cpp
919
+ using minstd_rand =
920
+ linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>;
921
  ```
922
 
923
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
924
  default-constructed object of type `minstd_rand` shall produce the value
925
  399268537.
926
 
927
  ``` cpp
928
+ using mt19937 =
929
+ mersenne_twister_engine<uint_fast32_t,
930
+ 32,624,397,31,0x9908b0df,11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253>;
931
  ```
932
 
933
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
934
  default-constructed object of type `mt19937` shall produce the value
935
  4123659995.
936
 
937
  ``` cpp
938
+ using mt19937_64 =
939
+ mersenne_twister_engine<uint_fast64_t,
940
  64,312,156,31,0xb5026f5aa96619e9,29,
941
  0x5555555555555555,17,
942
  0x71d67fffeda60000,37,
943
  0xfff7eee000000000,43,
944
+ 6364136223846793005>;
 
945
  ```
946
 
947
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
948
  default-constructed object of type `mt19937_64` shall produce the value
949
  9981545732273789042.
950
 
951
  ``` cpp
952
+ using ranlux24_base =
953
+ subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>;
954
  ```
955
 
956
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
957
  default-constructed object of type `ranlux24_base` shall produce the
958
  value 7937952.
959
 
960
  ``` cpp
961
+ using ranlux48_base =
962
+ subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>;
963
  ```
964
 
965
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
966
  default-constructed object of type `ranlux48_base` shall produce the
967
  value 61839128582725.
968
 
969
  ``` cpp
970
+ using ranlux24 = discard_block_engine<ranlux24_base, 223, 23>;
 
971
  ```
972
 
973
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
974
  default-constructed object of type `ranlux24` shall produce the value
975
  9901578.
976
 
977
  ``` cpp
978
+ using ranlux48 = discard_block_engine<ranlux48_base, 389, 11>;
 
979
  ```
980
 
981
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
982
  default-constructed object of type `ranlux48` shall produce the value
983
  249142670248501.
984
 
985
  ``` cpp
986
+ using knuth_b = shuffle_order_engine<minstd_rand0,256>;
 
987
  ```
988
 
989
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
990
  default-constructed object of type `knuth_b` shall produce the value
991
  1112339016.
992
 
993
  ``` cpp
994
+ using default_random_engine = implementation-defined;
 
995
  ```
996
 
997
+ *Remarks:* The choice of engine type named by this `typedef` is
998
+ *implementation-defined*.
999
+
1000
+ [*Note 1*: The implementation may select this type on the basis of
1001
+ performance, size, quality, or any combination of such factors, so as to
1002
+ provide at least acceptable engine behavior for relatively casual,
1003
+ inexpert, and/or lightweight use. Because different implementations may
1004
+ select different underlying engine types, code that uses this `typedef`
1005
+ need not generate identical sequences across
1006
+ implementations. — *end note*]
1007
 
1008
  ### Class `random_device` <a id="rand.device">[[rand.device]]</a>
1009
 
1010
+ A `random_device` uniform random bit generator produces nondeterministic
1011
+ random numbers.
1012
 
1013
+ If implementation limitations prevent generating nondeterministic random
1014
+ numbers, the implementation may employ a random number engine.
1015
 
1016
  ``` cpp
1017
+ class random_device {
 
1018
  public:
1019
  // types
1020
+ using result_type = unsigned int;
1021
 
1022
  // generator characteristics
1023
  static constexpr result_type min() { return numeric_limits<result_type>::min(); }
1024
  static constexpr result_type max() { return numeric_limits<result_type>::max(); }
1025
 
 
1040
 
1041
  ``` cpp
1042
  explicit random_device(const string& token = implementation-defined);
1043
  ```
1044
 
1045
+ *Effects:* Constructs a `random_device` nondeterministic uniform random
1046
+ bit generator object. The semantics and default value of the `token`
1047
+ parameter are *implementation-defined*. [^3]
1048
 
1049
+ *Throws:* A value of an *implementation-defined* type derived from
1050
  `exception` if the `random_device` could not be initialized.
1051
 
1052
  ``` cpp
1053
  double entropy() const noexcept;
1054
  ```
 
1059
 
1060
  ``` cpp
1061
  result_type operator()();
1062
  ```
1063
 
1064
+ *Returns:* A nondeterministic random value, uniformly distributed
1065
+ between `min()` and `max()`, inclusive. It is *implementation-defined*
1066
+ how these values are generated.
1067
 
1068
+ *Throws:* A value of an *implementation-defined* type derived from
1069
  `exception` if a random number could not be obtained.
1070
 
1071
  ### Utilities <a id="rand.util">[[rand.util]]</a>
1072
 
1073
  #### Class `seed_seq` <a id="rand.util.seedseq">[[rand.util.seedseq]]</a>
1074
 
1075
  ``` cpp
1076
+ class seed_seq {
 
1077
  public:
1078
  // types
1079
+ using result_type = uint_least32_t;
1080
 
1081
  // constructors
1082
  seed_seq();
1083
  template<class T>
1084
  seed_seq(initializer_list<T> il);
 
1088
  // generating functions
1089
  template<class RandomAccessIterator>
1090
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
1091
 
1092
  // property functions
1093
+ size_t size() const noexcept;
1094
  template<class OutputIterator>
1095
  void param(OutputIterator dest) const;
1096
 
1097
  // no copy functions
1098
  seed_seq(const seed_seq& ) = delete;
 
1142
  template<class RandomAccessIterator>
1143
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
1144
  ```
1145
 
1146
  *Requires:* `RandomAccessIterator` shall meet the requirements of a
1147
+ mutable random access iterator ([[random.access.iterators]]). Moreover,
 
1148
  `iterator_traits<RandomAccessIterator>::value_type` shall denote an
1149
  unsigned integer type capable of accommodating 32-bit quantities.
1150
 
1151
  *Effects:* Does nothing if `begin == end`. Otherwise, with
1152
  s = `v.size()` and n = `end` - `begin`, fills the supplied range
 
1157
 
1158
  *Throws:* What and when `RandomAccessIterator` operations of `begin` and
1159
  `end` throw.
1160
 
1161
  ``` cpp
1162
+ size_t size() const noexcept;
1163
  ```
1164
 
1165
  *Returns:* The number of 32-bit units that would be returned by a call
1166
  to `param()`.
1167
 
 
 
1168
  *Complexity:* Constant time.
1169
 
1170
  ``` cpp
1171
  template<class OutputIterator>
1172
  void param(OutputIterator dest) const;
1173
  ```
1174
 
1175
  *Requires:* `OutputIterator` shall satisfy the requirements of an output
1176
+ iterator ([[output.iterators]]). Moreover, the expression `*dest = rt`
1177
+ shall be valid for a value `rt` of type `result_type`.
 
1178
 
1179
  *Effects:* Copies the sequence of prepared 32-bit units to the given
1180
  destination, as if by executing the following statement:
1181
 
1182
  ``` cpp
 
1187
 
1188
  #### Function template `generate_canonical` <a id="rand.util.canonical">[[rand.util.canonical]]</a>
1189
 
1190
  Each function instantiated from the template described in this section 
1191
  [[rand.util.canonical]] maps the result of one or more invocations of a
1192
+ supplied uniform random bit generator `g` to one member of the specified
1193
+ `RealType` such that, if the values gᵢ produced by `g` are uniformly
1194
+ distributed, the instantiation’s results tⱼ, 0 ≤ tⱼ < 1, are distributed
1195
+ as uniformly as possible as specified below.
1196
 
1197
+ [*Note 1*: Obtaining a value in this way can be a useful step in the
1198
+ process of transforming a value generated by a uniform random bit
1199
+ generator into a value that can be delivered by a random number
1200
+ distribution. — *end note*]
1201
 
1202
  ``` cpp
1203
+ template<class RealType, size_t bits, class URBG>
1204
+ RealType generate_canonical(URBG& g);
1205
  ```
1206
 
1207
  *Complexity:* Exactly k = max(1, ⌈ b / log₂ R ⌉) invocations of `g`,
1208
  where b[^5] is the lesser of `numeric_limits<RealType>::digits` and
1209
  `bits`, and R is the value of `g.max()` - `g.min()` + 1.
 
1231
  particular, declarations for copy constructors, for copy assignment
1232
  operators, for streaming operators, and for equality and inequality
1233
  operators are not shown in the synopses.
1234
 
1235
  The algorithms for producing each of the specified distributions are
1236
+ *implementation-defined*.
1237
 
1238
  The value of each probability density function p(z) and of each discrete
1239
  probability function P(zᵢ) specified in this section is 0 everywhere
1240
  outside its stated domain.
1241
 
 
1249
  P(i\,|\,a,b) = 1 / (b - a + 1)
1250
  \; \mbox{.}$$
1251
 
1252
  ``` cpp
1253
  template<class IntType = int>
1254
+ class uniform_int_distribution {
 
1255
  public:
1256
  // types
1257
+ using result_type = IntType;
1258
+ using param_type = unspecified;
1259
 
1260
  // constructors and reset functions
1261
  explicit uniform_int_distribution(IntType a = 0, IntType b = numeric_limits<IntType>::max());
1262
  explicit uniform_int_distribution(const param_type& parm);
1263
  void reset();
1264
 
1265
  // generating functions
1266
+ template<class URBG>
1267
+ result_type operator()(URBG& g);
1268
+ template<class URBG>
1269
+ result_type operator()(URBG& g, const param_type& parm);
1270
 
1271
  // property functions
1272
  result_type a() const;
1273
  result_type b() const;
1274
  param_type param() const;
 
1307
  numbers x, a ≤ x < b, distributed according to the constant probability
1308
  density function $$%
1309
  p(x\,|\,a,b) = 1 / (b - a)
1310
  \; \mbox{.}$$
1311
 
1312
+ [*Note 1*: This implies that p(x | a,b) is undefined when
1313
+ `a == b`. — *end note*]
1314
+
1315
  ``` cpp
1316
  template<class RealType = double>
1317
+ class uniform_real_distribution {
 
1318
  public:
1319
  // types
1320
+ using result_type = RealType;
1321
+ using param_type = unspecified;
1322
 
1323
  // constructors and reset functions
1324
  explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
1325
  explicit uniform_real_distribution(const param_type& parm);
1326
  void reset();
1327
 
1328
  // generating functions
1329
+ template<class URBG>
1330
+ result_type operator()(URBG& g);
1331
+ template<class URBG>
1332
+ result_type operator()(URBG& g, const param_type& parm);
1333
 
1334
  // property functions
1335
  result_type a() const;
1336
  result_type b() const;
1337
  param_type param() const;
 
1376
  1-p & \mbox{if} & b = \tcode{false}
1377
  \end{array}\right.
1378
  \; \mbox{.}$$
1379
 
1380
  ``` cpp
1381
+ class bernoulli_distribution {
 
1382
  public:
1383
  // types
1384
+ using result_type = bool;
1385
+ using param_type = unspecified;
1386
 
1387
  // constructors and reset functions
1388
  explicit bernoulli_distribution(double p = 0.5);
1389
  explicit bernoulli_distribution(const param_type& parm);
1390
  void reset();
1391
 
1392
  // generating functions
1393
+ template<class URBG>
1394
+ result_type operator()(URBG& g);
1395
+ template<class URBG>
1396
+ result_type operator()(URBG& g, const param_type& parm);
1397
 
1398
  // property functions
1399
  double p() const;
1400
  param_type param() const;
1401
  void param(const param_type& parm);
 
1429
  = \binom{t}{i} \cdot p^i \cdot (1-p)^{t-i}
1430
  \; \mbox{.}$$
1431
 
1432
  ``` cpp
1433
  template<class IntType = int>
1434
+ class binomial_distribution {
 
1435
  public:
1436
  // types
1437
+ using result_type = IntType;
1438
+ using param_type = unspecified;
1439
 
1440
  // constructors and reset functions
1441
  explicit binomial_distribution(IntType t = 1, double p = 0.5);
1442
  explicit binomial_distribution(const param_type& parm);
1443
  void reset();
1444
 
1445
  // generating functions
1446
+ template<class URBG>
1447
+ result_type operator()(URBG& g);
1448
+ template<class URBG>
1449
+ result_type operator()(URBG& g, const param_type& parm);
1450
 
1451
  // property functions
1452
  IntType t() const;
1453
  double p() const;
1454
  param_type param() const;
 
1490
  = p \cdot (1-p)^{i}
1491
  \; \mbox{.}$$
1492
 
1493
  ``` cpp
1494
  template<class IntType = int>
1495
+ class geometric_distribution {
 
1496
  public:
1497
  // types
1498
+ using result_type = IntType;
1499
+ using param_type = unspecified;
1500
 
1501
  // constructors and reset functions
1502
  explicit geometric_distribution(double p = 0.5);
1503
  explicit geometric_distribution(const param_type& parm);
1504
  void reset();
1505
 
1506
  // generating functions
1507
+ template<class URBG>
1508
+ result_type operator()(URBG& g);
1509
+ template<class URBG>
1510
+ result_type operator()(URBG& g, const param_type& parm);
1511
 
1512
  // property functions
1513
  double p() const;
1514
  param_type param() const;
1515
  void param(const param_type& parm);
 
1541
  function $$%
1542
  P(i\,|\,k,p)
1543
  = \binom{k+i-1}{i} \cdot p^k \cdot (1-p)^i
1544
  \; \mbox{.}$$
1545
 
1546
+ [*Note 1*: This implies that P(i | k,p) is undefined when
1547
+ `p == 1`. — *end note*]
1548
+
1549
  ``` cpp
1550
  template<class IntType = int>
1551
+ class negative_binomial_distribution {
 
1552
  public:
1553
  // types
1554
+ using result_type = IntType;
1555
+ using param_type = unspecified;
1556
 
1557
  // constructor and reset functions
1558
  explicit negative_binomial_distribution(IntType k = 1, double p = 0.5);
1559
  explicit negative_binomial_distribution(const param_type& parm);
1560
  void reset();
1561
 
1562
  // generating functions
1563
+ template<class URBG>
1564
+ result_type operator()(URBG& g);
1565
+ template<class URBG>
1566
+ result_type operator()(URBG& g, const param_type& parm);
1567
 
1568
  // property functions
1569
  IntType k() const;
1570
  double p() const;
1571
  param_type param() const;
 
1615
  template<class IntType = int>
1616
  class poisson_distribution
1617
  {
1618
  public:
1619
  // types
1620
+ using result_type = IntType;
1621
+ using param_type = unspecified;
1622
 
1623
  // constructors and reset functions
1624
  explicit poisson_distribution(double mean = 1.0);
1625
  explicit poisson_distribution(const param_type& parm);
1626
  void reset();
1627
 
1628
  // generating functions
1629
+ template<class URBG>
1630
+ result_type operator()(URBG& g);
1631
+ template<class URBG>
1632
+ result_type operator()(URBG& g, const param_type& parm);
1633
 
1634
  // property functions
1635
  double mean() const;
1636
  param_type param() const;
1637
  void param(const param_type& parm);
 
1665
  = \lambda e^{-\lambda x}
1666
  \; \mbox{.}$$
1667
 
1668
  ``` cpp
1669
  template<class RealType = double>
1670
+ class exponential_distribution {
 
1671
  public:
1672
  // types
1673
+ using result_type = RealType;
1674
+ using param_type = unspecified;
1675
 
1676
  // constructors and reset functions
1677
  explicit exponential_distribution(RealType lambda = 1.0);
1678
  explicit exponential_distribution(const param_type& parm);
1679
  void reset();
1680
 
1681
  // generating functions
1682
+ template<class URBG>
1683
+ result_type operator()(URBG& g);
1684
+ template<class URBG>
1685
+ result_type operator()(URBG& g, const param_type& parm);
1686
 
1687
  // property functions
1688
  RealType lambda() const;
1689
  param_type param() const;
1690
  void param(const param_type& parm);
 
1697
  explicit exponential_distribution(RealType lambda = 1.0);
1698
  ```
1699
 
1700
  *Requires:* 0 < `lambda`.
1701
 
1702
+ *Effects:* Constructs an `exponential_distribution` object; `lambda`
1703
  corresponds to the parameter of the distribution.
1704
 
1705
  ``` cpp
1706
  RealType lambda() const;
1707
  ```
 
1719
  \, \cdot \, x^{\, \alpha-1}
1720
  \; \mbox{.}$$
1721
 
1722
  ``` cpp
1723
  template<class RealType = double>
1724
+ class gamma_distribution {
 
1725
  public:
1726
  // types
1727
+ using result_type = RealType;
1728
+ using param_type = unspecified;
1729
 
1730
  // constructors and reset functions
1731
  explicit gamma_distribution(RealType alpha = 1.0, RealType beta = 1.0);
1732
  explicit gamma_distribution(const param_type& parm);
1733
  void reset();
1734
 
1735
  // generating functions
1736
+ template<class URBG>
1737
+ result_type operator()(URBG& g);
1738
+ template<class URBG>
1739
+ result_type operator()(URBG& g, const param_type& parm);
1740
 
1741
  // property functions
1742
  RealType alpha() const;
1743
  RealType beta() const;
1744
  param_type param() const;
 
1782
  \cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
1783
  \; \mbox{.}$$
1784
 
1785
  ``` cpp
1786
  template<class RealType = double>
1787
+ class weibull_distribution {
 
1788
  public:
1789
  // types
1790
+ using result_type = RealType;
1791
+ using param_type = unspecified;
1792
 
1793
  // constructor and reset functions
1794
  explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0);
1795
  explicit weibull_distribution(const param_type& parm);
1796
  void reset();
1797
 
1798
  // generating functions
1799
+ template<class URBG>
1800
+ result_type operator()(URBG& g);
1801
+ template<class URBG>
1802
+ result_type operator()(URBG& g, const param_type& parm);
1803
 
1804
  // property functions
1805
  RealType a() const;
1806
  RealType b() const;
1807
  param_type param() const;
 
1846
  \right)
1847
  \; \mbox{.}$$
1848
 
1849
  ``` cpp
1850
  template<class RealType = double>
1851
+ class extreme_value_distribution {
 
1852
  public:
1853
  // types
1854
+ using result_type = RealType;
1855
+ using param_type = unspecified;
1856
 
1857
  // constructor and reset functions
1858
  explicit extreme_value_distribution(RealType a = 0.0, RealType b = 1.0);
1859
  explicit extreme_value_distribution(const param_type& parm);
1860
  void reset();
1861
 
1862
  // generating functions
1863
+ template<class URBG>
1864
+ result_type operator()(URBG& g);
1865
+ template<class URBG>
1866
+ result_type operator()(URBG& g, const param_type& parm);
1867
 
1868
  // property functions
1869
  RealType a() const;
1870
  RealType b() const;
1871
  param_type param() const;
 
1915
  \; \mbox{.}$$ The distribution parameters μ and σ are also known as this
1916
  distribution’s *mean* and *standard deviation* .
1917
 
1918
  ``` cpp
1919
  template<class RealType = double>
1920
+ class normal_distribution {
 
1921
  public:
1922
  // types
1923
+ using result_type = RealType;
1924
+ using param_type = unspecified;
1925
 
1926
  // constructors and reset functions
1927
  explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0);
1928
  explicit normal_distribution(const param_type& parm);
1929
  void reset();
1930
 
1931
  // generating functions
1932
+ template<class URBG>
1933
+ result_type operator()(URBG& g);
1934
+ template<class URBG>
1935
+ result_type operator()(URBG& g, const param_type& parm);
1936
 
1937
  // property functions
1938
  RealType mean() const;
1939
  RealType stddev() const;
1940
  param_type param() const;
 
1982
  }
1983
  \; \mbox{.}$$
1984
 
1985
  ``` cpp
1986
  template<class RealType = double>
1987
+ class lognormal_distribution {
 
1988
  public:
1989
  // types
1990
+ using result_type = RealType;
1991
+ using param_type = unspecified;
1992
 
1993
  // constructor and reset functions
1994
  explicit lognormal_distribution(RealType m = 0.0, RealType s = 1.0);
1995
  explicit lognormal_distribution(const param_type& parm);
1996
  void reset();
1997
 
1998
  // generating functions
1999
+ template<class URBG>
2000
+ result_type operator()(URBG& g);
2001
+ template<class URBG>
2002
+ result_type operator()(URBG& g, const param_type& parm);
2003
 
2004
  // property functions
2005
  RealType m() const;
2006
  RealType s() const;
2007
  param_type param() const;
 
2044
  {\Gamma(n/2) \cdot 2^{n/2}}
2045
  \; \mbox{.}$$
2046
 
2047
  ``` cpp
2048
  template<class RealType = double>
2049
+ class chi_squared_distribution {
 
2050
  public:
2051
  // types
2052
+ using result_type = RealType;
2053
+ using param_type = unspecified;
2054
 
2055
  // constructor and reset functions
2056
  explicit chi_squared_distribution(RealType n = 1);
2057
  explicit chi_squared_distribution(const param_type& parm);
2058
  void reset();
2059
 
2060
  // generating functions
2061
+ template<class URBG>
2062
+ result_type operator()(URBG& g);
2063
+ template<class URBG>
2064
+ result_type operator()(URBG& g, const param_type& parm);
2065
 
2066
  // property functions
2067
  RealType n() const;
2068
  param_type param() const;
2069
  void param(const param_type& parm);
 
2096
  = \left( \pi b \left( 1 + \left( \frac{x-a}{b} \right)^2 \;\right)\right)^{-1}
2097
  \; \mbox{.}$$
2098
 
2099
  ``` cpp
2100
  template<class RealType = double>
2101
+ class cauchy_distribution {
 
2102
  public:
2103
  // types
2104
+ using result_type = RealType;
2105
+ using param_type = unspecified;
2106
 
2107
  // constructor and reset functions
2108
  explicit cauchy_distribution(RealType a = 0.0, RealType b = 1.0);
2109
  explicit cauchy_distribution(const param_type& parm);
2110
  void reset();
2111
 
2112
  // generating functions
2113
+ template<class URBG>
2114
+ result_type operator()(URBG& g);
2115
+ template<class URBG>
2116
+ result_type operator()(URBG& g, const param_type& parm);
2117
 
2118
  // property functions
2119
  RealType a() const;
2120
  RealType b() const;
2121
  param_type param() const;
 
2164
  {\left( 1 + \frac{m x}{n} \right)}^{-(m+n)/2}
2165
  \; \mbox{.}$$
2166
 
2167
  ``` cpp
2168
  template<class RealType = double>
2169
+ class fisher_f_distribution {
 
2170
  public:
2171
  // types
2172
+ using result_type = RealType;
2173
+ using param_type = unspecified;
2174
 
2175
  // constructor and reset functions
2176
  explicit fisher_f_distribution(RealType m = 1, RealType n = 1);
2177
  explicit fisher_f_distribution(const param_type& parm);
2178
  void reset();
2179
 
2180
  // generating functions
2181
+ template<class URBG>
2182
+ result_type operator()(URBG& g);
2183
+ template<class URBG>
2184
+ result_type operator()(URBG& g, const param_type& parm);
2185
 
2186
  // property functions
2187
  RealType m() const;
2188
  RealType n() const;
2189
  param_type param() const;
 
2228
  \cdot \left( 1+\frac{x^2}{n} \right) ^ {-(n+1)/2}
2229
  \; \mbox{.}$$
2230
 
2231
  ``` cpp
2232
  template<class RealType = double>
2233
+ class student_t_distribution {
 
2234
  public:
2235
  // types
2236
+ using result_type = RealType;
2237
+ using param_type = unspecified;
2238
 
2239
  // constructor and reset functions
2240
  explicit student_t_distribution(RealType n = 1);
2241
  explicit student_t_distribution(const param_type& parm);
2242
  void reset();
2243
 
2244
  // generating functions
2245
+ template<class URBG>
2246
+ result_type operator()(URBG& g);
2247
+ template<class URBG>
2248
+ result_type operator()(URBG& g, const param_type& parm);
2249
 
2250
  // property functions
2251
  RealType n() const;
2252
  param_type param() const;
2253
  void param(const param_type& parm);
 
2289
  non-NaN, and non-infinity. Moreover, the following relation shall hold:
2290
  0 < S = w₀ + ⋯ + wₙ₋₁.
2291
 
2292
  ``` cpp
2293
  template<class IntType = int>
2294
+ class discrete_distribution {
 
2295
  public:
2296
  // types
2297
+ using result_type = IntType;
2298
+ using param_type = unspecified;
2299
 
2300
  // constructor and reset functions
2301
  discrete_distribution();
2302
  template<class InputIterator>
2303
  discrete_distribution(InputIterator firstW, InputIterator lastW);
 
2306
  discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
2307
  explicit discrete_distribution(const param_type& parm);
2308
  void reset();
2309
 
2310
  // generating functions
2311
+ template<class URBG>
2312
+ result_type operator()(URBG& g);
2313
+ template<class URBG>
2314
+ result_type operator()(URBG& g, const param_type& parm);
2315
 
2316
  // property functions
2317
  vector<double> probabilities() const;
2318
  param_type param() const;
2319
  void param(const param_type& parm);
 
2325
  ``` cpp
2326
  discrete_distribution();
2327
  ```
2328
 
2329
  *Effects:* Constructs a `discrete_distribution` object with n = 1 and
2330
+ p₀ = 1.
2331
+
2332
+ [*Note 1*: Such an object will always deliver the value
2333
+ 0. — *end note*]
2334
 
2335
  ``` cpp
2336
  template<class InputIterator>
2337
  discrete_distribution(InputIterator firstW, InputIterator lastW);
2338
  ```
2339
 
2340
  *Requires:* `InputIterator` shall satisfy the requirements of an input
2341
+ iterator ([[input.iterators]]). Moreover,
2342
  `iterator_traits<InputIterator>::value_type` shall denote a type that is
2343
  convertible to `double`. If `firstW == lastW`, let n = 1 and w₀ = 1.
2344
  Otherwise, [`firstW`, `lastW`) shall form a sequence w of length n > 0.
2345
 
2346
  *Effects:* Constructs a `discrete_distribution` object with
 
2401
  non-infinity. Moreover, the following relation shall hold:
2402
  0 < S = w₀ + ⋯ + wₙ₋₁.
2403
 
2404
  ``` cpp
2405
  template<class RealType = double>
2406
+ class piecewise_constant_distribution {
 
2407
  public:
2408
  // types
2409
+ using result_type = RealType;
2410
+ using param_type = unspecified;
2411
 
2412
  // constructor and reset functions
2413
  piecewise_constant_distribution();
2414
  template<class InputIteratorB, class InputIteratorW>
2415
  piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
2416
  InputIteratorW firstW);
2417
  template<class UnaryOperation>
2418
  piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
2419
  template<class UnaryOperation>
2420
+ piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax,
2421
+ UnaryOperation fw);
2422
  explicit piecewise_constant_distribution(const param_type& parm);
2423
  void reset();
2424
 
2425
  // generating functions
2426
+ template<class URBG>
2427
+ result_type operator()(URBG& g);
2428
+ template<class URBG>
2429
+ result_type operator()(URBG& g, const param_type& parm);
2430
 
2431
  // property functions
2432
  vector<result_type> intervals() const;
2433
  vector<result_type> densities() const;
2434
  param_type param() const;
 
2541
  \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k)
2542
  \; \mbox{.}$$
2543
 
2544
  ``` cpp
2545
  template<class RealType = double>
2546
+ class piecewise_linear_distribution {
 
2547
  public:
2548
  // types
2549
+ using result_type = RealType;
2550
+ using param_type = unspecified;
2551
 
2552
  // constructor and reset functions
2553
  piecewise_linear_distribution();
2554
  template<class InputIteratorB, class InputIteratorW>
2555
  piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
 
2560
  piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
2561
  explicit piecewise_linear_distribution(const param_type& parm);
2562
  void reset();
2563
 
2564
  // generating functions
2565
+ template<class URBG>
2566
+ result_type operator()(URBG& g);
2567
+ template<class URBG>
2568
+ result_type operator()(URBG& g, const param_type& parm);
2569
 
2570
  // property functions
2571
  vector<result_type> intervals() const;
2572
  vector<result_type> densities() const;
2573
  param_type param() const;
 
2653
 
2654
  *Returns:* A `vector<result_type>` whose `size` member returns n and
2655
  whose `operator[]` member returns ρₖ when invoked with argument k for
2656
  k = 0, …, n.
2657
 
2658
+ ### Low-quality random number generation <a id="c.math.rand">[[c.math.rand]]</a>
2659
+
2660
+ [*Note 1*: The header `<cstdlib>` ([[cstdlib.syn]]) declares the
2661
+ functions described in this subclause. — *end note*]
2662
+
2663
+ ``` cpp
2664
+ int rand();
2665
+ void srand(unsigned int seed);
2666
+ ```
2667
+
2668
+ *Effects:* The `rand` and `srand` functions have the semantics specified
2669
+ in the C standard library.
2670
+
2671
+ *Remarks:* The implementation may specify that particular library
2672
+ functions may call `rand`. It is *implementation-defined* whether the
2673
+ `rand` function may introduce data races ([[res.on.data.races]]).
2674
+
2675
+ [*Note 1*: The other random number generation facilities in this
2676
+ International Standard ([[rand]]) are often preferable to `rand`,
2677
+ because `rand`’s underlying algorithm is unspecified. Use of `rand`
2678
+ therefore continues to be non-portable, with unpredictable and
2679
+ oft-questionable quality and performance. — *end note*]
2680
+
2681
+ ISO C 7.22.2
2682
+