What is a solution to generate random long long
with cryptographic strength С++? (boost is allowed)
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Under linux you can read from
/dev/random
or/dev/urandom
They both provide cryptographic entropy.
Difference between them being:
/dev/random
blocks if entropy is exhausted, therefore it could be slower than/dev/urandom
but is "stronger"So, using streams it will look like this
The
<random>
header provides portable access to random number facilities including, potentially, a cryptographic pRNG.std::random_device
may not be a cryptographic pRNG on all implementations, so you'll have to check your implementation documentation. In particular VC++ before 2012 does not provide a non-deterministic implementation. VC++ 2012 and later implements this using Windows cryptography services.Implementations on other operating systems such as Linux or Mac OS X can commonly use "/dev/urandom" or "/dev/random" or any other random device exposed via the filesystem. E.g. libc++ uses "/dev/urandom" by default, which on OS X uses the Yarrow algorithm.
I know you ruled out boost, but
boost::random_device
has an implementation for Windows that uses that platform's cryptography services.