std::random_device::random_device
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody> explicit random_device(const std::string& token = /*implementation-defined*/ ); |
(dal C++11) | |
Costruisce un nuovo oggetto std::random_device, avvalendosi della
token argomento, se previsto, in attuazione definito modo. Original:
Constructs a new std::random_device object, making use of the argument
token, if provided, in implementation-defined manner. 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.
Applicazione tipica su un sistema Linux, per esempio, si aspetta
token di essere il nome di un dispositivo a caratteri che produce numeri casuali lettura da, con il valore predefinito "/dev/urandom".Original:
Typical implementation on a Linux system, for example, expects
token to be the name of a character device that produces random numbers when read from, with the default value "/dev/urandom".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.
Eccezioni
Genera un applicazione definite le eccezioni derivate da std::exception in caso di fallimento.
Original:
Throws an implementation-defined exceptions derived from std::exception on failure.
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.
Esempio
Vengono illustrati i due tipi comunemente disponibili di
std::random_device su Linux
Original:
Demonstrates the two commonly available types of
std::random_device on Linux
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.
#include <iostream>
#include <random>
int main()
{
std::uniform_int_distribution<int> d(0, 10);
std::random_device rd1; // uses /dev/urandom
for(int n = 0; n < 10; ++n)
std::cout << d(rd1) << ' ';
std::cout << '\n';
std::random_device rd2("/dev/random"); // much slower on Linux
for(int n = 0; n < 10; ++n)
std::cout << d(rd2) << ' ';
std::cout << '\n';
}
Output:
7 10 7 0 4 4 6 9 4 7
2 4 10 6 3 2 0 6 3 7