std::random_device::random_device
De cppreference.com
|
|
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
explicit random_device(const std::string& token = /*implementation-defined*/ ); |
(desde C++11) | |
Construye un objeto std::random_device nuevo, haciendo uso de la
token argumento, si se proporciona, en aplicación definida por el 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.
Implementación típica en un sistema Linux, por ejemplo, espera
token a ser el nombre de un dispositivo de caracteres que produce números aleatorios cuando se leen de, con el valor por defecto "/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.
Excepciones
Lanza una excepción definidos implementación derivados de std::exception en caso de fallo .
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.
Ejemplo
Demuestra los dos tipos comúnmente disponibles de
std::random_device en 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.
Ejecuta este código
#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';
}
Salida:
7 10 7 0 4 4 6 9 4 7
2 4 10 6 3 2 0 6 3 7