[cfe-dev] [EXTERNAL] RE: [libc++] Porting libc++ to embedded targets/compilers

Nagurne, James via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 13 10:50:09 PDT 2017


I would agree that the original intent of random_device is to provide truly random numbers. However there is an explicit clause (ยง26.5.6.2 in the C++14 standard) that blesses the use of a random number engine for implementations where non-deterministic random numbers are not supported.

JB

From: Ben Craig [mailto:ben.craig at ni.com]
Sent: Wednesday, September 13, 2017 8:39 AM
To: Nagurne, James; cfe-dev at lists.llvm.org
Subject: [EXTERNAL] RE: [libc++] Porting libc++ to embedded targets/compilers

>- The implementation of std::random_device does not support utilizing a random number engine in the absence of implementation-specific non-deterministic RNGs
>Two third-party library solutions, arc4 and Sodium, and two /platform-specific solutions, Unix-like /dev/random and Microsoft srand_s are supported.
>Could a fallback macro be used to implement random_device via another engine found in the random header? I think std::mt19937 is the simplest random engine that supports the full range of values of unsigned int.

The intent of the standard and the expectation of users is that std::random_device provide true random (and not pseudo-random) numbers.  In my opinion, it is better to omit std::random_device than it would be to make it provide pseudo-random numbers.  If a user only needs pseudo-random numbers, then they can directly use the pseudo-random facilities.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170913/783a7e59/attachment.html>


More information about the cfe-dev mailing list