[rand.device] # 29 Numerics library [[numerics]](./#numerics) ## 29.5 Random number generation [[rand]](rand#device) ### 29.5.7 Class random_device [rand.device] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4027) A random_device uniform random bit generator produces nondeterministic random numbers[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4032) If implementation limitations prevent generating nondeterministic random numbers, the implementation may employ a random number engine[.](#2.sentence-1) [🔗](#lib:random_device_) namespace std {class random_device {public:// typesusing result_type = unsigned int; // generator characteristicsstatic constexpr result_type min() { return numeric_limits::min(); }static constexpr result_type max() { return numeric_limits::max(); }// constructors random_device() : random_device(*implementation-defined*) {}explicit random_device(const string& token); // generating functions result_type operator()(); // property functionsdouble entropy() const noexcept; // no copy functions random_device(const random_device&) = delete; void operator=(const random_device&) = delete; };} [🔗](#lib:random_device,constructor) `explicit random_device(const string& token); ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4074) *Throws*: A value of an implementation-defined type derived from exception if the random_device cannot be initialized[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4080) *Remarks*: The semantics of the token parameter and the token value used by the default constructor are implementation-defined[.](#4.sentence-1)[243](#footnote-243 "The parameter is intended to allow an implementation to differentiate between different sources of randomness.") [🔗](#lib:entropy,random_device) `double entropy() const noexcept; ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4098) *Returns*: If the implementation employs a random number engine, returns 0.0[.](#5.sentence-1) Otherwise, returns an entropy estimate[244](#footnote-244 "If a device has n states whose respective probabilities are �…�, the device entropy S is defined as S = - ∑�.") for the random numbers returned by operator(), in the range min() to log2(max()+1)[.](#5.sentence-2) [🔗](#lib:operator(),random_device) `result_type operator()(); ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4123) *Returns*: A nondeterministic random value, uniformly distributed between min() and max() (inclusive)[.](#6.sentence-1) It is implementation-defined how these values are generated[.](#6.sentence-2) [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L4131) *Throws*: A value of an implementation-defined type derived from exception if a random number cannot be obtained[.](#7.sentence-1) [243)](#footnote-243)[243)](#footnoteref-243) The parameter is intended to allow an implementation to differentiate between different sources of randomness[.](#footnote-243.sentence-1) [244)](#footnote-244)[244)](#footnoteref-244) If a device has n states whose respective probabilities are P0,…,Pn−1, the device entropy S is defined as S=−∑n−1i=0Piâ‹logPi[.](#footnote-244.sentence-2)