How would I make a random seed / hash to make Rand really random?

how would I generate a seed or hash that would make rand actually random? I need him to change every time he selects a number. New in C ++, so I'm not quite sure how to do this. Thank you !: D

+6
source share
2 answers

With C ++ 11 you can use std::random_device . I suggest you look at the link for a detailed guide.

Extracting a substantial message from a video call: you should never use srand and rand , but instead use std::random_device and std::mt19937 - for most cases you will need the following:

 #include <iostream> #include <random> int main() { std::random_device rd; std::mt19937 mt(rd()); std::uniform_int_distribution<int> dist(0,99); for (int i = 0; i < 16; i++) { std::cout << dist(mt) << " "; } std::cout << std::endl; } 
+5
source

There is no such thing as a “virtually random” random number generator without sample environmental data or access to a quantum random number source. Consider accessing the source of ANU random numbers if you need truly random numbers ( http://qrng.anu.edu.au/FAQ.php#api ).

Otherwise, Boost provides a more robust pseudo-RNG, which should be enough for most purposes: http://www.boost.org/doc/libs/1_58_0/doc/html/boost_random.html

+1
source

All Articles