C++ Logo

std-proposals

Advanced search

Re: Comments for P0205 and P2060: Mersenne twister can actually generate 7 and 13

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Wed, 17 Nov 2021 22:05:15 +0000
Hi,

On Wed, 17 Nov 2021 18:26:41 +0000
Dimitrij Mijoski via Std-Proposals <std-proposals_at_[hidden]>
wrote:

> I personally think that filling the whole state (624 integers) with
> values from random_device is wrong because it wastes the system
> entropy. If not wrong then slow and pointless. I consider the
> following code to be bad.
>
> #include <random>
> using namespace std;
>
> int main()
> {
> random_device rd;
> unsigned int v[624]; // no need for this large seed
> for(auto& a: v)
> a = rd();
> seed_seq sd(begin(v), end(v));
> auto g = mt19937(sd);
> }

random_device random number sources by standard library:
* libstdc++ : /dev/urandom by default
* libc++ : getentropy() which uses getrandom()
* MS STL : rand_s() which in turn uses RtlGenRandom()

Reading from /dev/urandom or using getentropy() doesn't deplete OS
entropy. I didn't find any documentation for rand_s(). However MS STL's
random_device::entropy() just return 32, so my bet that it doesn't
deplete entropy either.

Cheers,
Lénárd

Received on 2021-11-17 16:05:25