std::random_device
De cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Déclaré dans l'en-tête <random>
|
||
class random_device; |
(depuis C++11) | |
std::random_device
est uniformément distribuée un générateur de nombre aléatoire entier, qui produit non déterministes nombres aléatoires, si une source non-déterministe (par exemple, un dispositif matériel) est disponible pour la mise en oeuvre .Original:
std::random_device
is a uniformly-distributed integer random number generator, which produces non-deterministic random numbers, if a non-deterministic source (e.g. a hardware device) is available to the implementation.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Types de membres
Type de membre
Original: Member type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
result_type
|
unsigned int |
Les fonctions membres
Original: Construction The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
operator= ( supprimée )Original: deleted The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
l'opérateur d'affectation est supprimé Original: the assignment operator is deleted The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique) |
Original: Generation The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |
Original: Characteristics The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Exemple
#include <iostream> #include <string> #include <map> #include <random> int main() { std::random_device rd; std::map<int, int> hist; for(int n=0; n<20000; ++n) ++hist[rd()%10]; for(auto p : hist) std::cout << p.first << " : " << std::string(p.second/100, '*') << '\n'; }
Résultat :
0 : ******************** 1 : ******************* 2 : ******************** 3 : ******************** 4 : ******************** 5 : ******************* 6 : ******************** 7 : ******************** 8 : ******************* 9 : ********************