This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

96
cppdraft/rand/general.md Normal file
View File

@@ -0,0 +1,96 @@
[rand.general]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#general)
### 29.5.1 General [rand.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1279)
Subclause [[rand]](rand "29.5Random number generation") defines a facility
for generating (pseudo-)random numbers[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1283)
In addition to a few utilities,
four categories of entities are described:[*uniform random bit generators*](#def:uniform_random_bit_generators),[*random number engines*](#def:random_number_engines),[*random number engine adaptors*](#def:random_number_engine_adaptors),
and[*random number distributions*](#def:random_number_distributions)[.](#2.sentence-1)
These categorizations are applicable
to types that meet the corresponding requirements,
to objects instantiated from such types,
and to templates producing such types when instantiated[.](#2.sentence-2)
[*Note [1](#note-1)*:
These entities are specified in such a way
as to permit the binding
of any uniform random bit generator object e as the argument
to any random number distribution object d,
thus producing a zero-argument function object
such as given by bind(d,e)[.](#2.sentence-3)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1306)
Each of the entities specified in [[rand]](rand "29.5Random number generation") has an associated arithmetic type ([[basic.fundamental]](basic.fundamental "6.9.2Fundamental types"))
identified as result_type[.](#3.sentence-1)
With T as the result_type thus associated with such an entity,
that entity is characterized:
- [(3.1)](#3.1)
as [*boolean*](#def:boolean) or equivalently as [*boolean-valued*](#def:boolean-valued),
if T is bool;
- [(3.2)](#3.2)
otherwise
as [*integral*](#def:integral) or equivalently as [*integer-valued*](#def:integer-valued),
if numeric_limits<T>::is_integer is true;
- [(3.3)](#3.3)
otherwise
as [*floating-point*](#def:floating-point) or equivalently as [*real-valued*](#def:real-valued)[.](#3.sentence-2)
If integer-valued,
an entity may optionally be further characterized as[*signed*](#def:signed) or [*unsigned*](#def:unsigned),
according to numeric_limits<T>::is_signed[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1331)
Unless otherwise specified,
all descriptions of calculations
in [[rand]](rand "29.5Random number generation") use mathematical real numbers[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1337)
Throughout [[rand]](rand "29.5Random number generation"),
the operatorsbitand, bitor, and xor denote the respective conventional bitwise operations[.](#5.sentence-1)
Further:
- [(5.1)](#5.1)
the operator rshift denotes a bitwise right shift
with zero-valued bits appearing in the high bits of the result, and
- [(5.2)](#5.2)
the operator lshiftw denotes a bitwise left shift
with zero-valued bits appearing in the low bits of the result,
and whose result is always taken modulo 2w[.](#5.sentence-2)