Files
cppdraft_translate/cppdraft/rand/device.md
2025-10-25 03:02:53 +03:00

3.6 KiB
Raw Blame History

[rand.device]

29 Numerics library [numerics]

29.5 Random number generation [rand]

29.5.7 Class random_device [rand.device]

1

#

A random_device uniform random bit generator produces nondeterministic random numbers.

2

#

If implementation limitations prevent generating nondeterministic random numbers, the implementation may employ a random number engine.

🔗

namespace std {class random_device {public:// typesusing result_type = unsigned int; // generator characteristicsstatic constexpr result_type min() { return numeric_limits<result_type>::min(); }static constexpr result_type max() { return numeric_limits<result_type>::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; };}

🔗

explicit random_device(const string& token);

3

#

Throws: A value of an implementation-defined type derived from exception if the random_device cannot be initialized.

4

#

Remarks: The semantics of the token parameter and the token value used by the default constructor are implementation-defined.243

🔗

double entropy() const noexcept;

5

#

Returns: If the implementation employs a random number engine, returns 0.0.

Otherwise, returns an entropy estimate244 for the random numbers returned by operator(), in the range min() to log2(max()+1).

🔗

result_type operator()();

6

#

Returns: A nondeterministic random value, uniformly distributed between min() and max() (inclusive).

It is implementation-defined how these values are generated.

7

#

Throws: A value of an implementation-defined type derived from exception if a random number cannot be obtained.

243)243)

The parameter is intended to allow an implementation to differentiate between different sources of randomness.

244)244)

If a device has n states whose respective probabilities are P0,…,Pn−1, the device entropy S is defined as

S=−∑ˆ’1i=0Piâ‹logPi.