std::rand
![]() |
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í. |
Definido en el archivo de encabezado <cstdlib>
|
||
int rand(); |
||
RAND_MAX
(0 y RAND_MAX incluido) .RAND_MAX
(0 and RAND_MAX included).You can help to correct and verify the translation. Click here for instructions.
srand()
debe ser llamada antes de cualquier llamada a rand()
para inicializar el generador de números aleatorios .srand()
should be called before any calls to rand()
to initialize the random number generator.You can help to correct and verify the translation. Click here for instructions.
Contenido |
[editar] Parámetros
You can help to correct and verify the translation. Click here for instructions.
[editar] Valor de retorno
RAND_MAX
RAND_MAX
.You can help to correct and verify the translation. Click here for instructions.
[editar] Ejemplo
#include <cstdlib> #include <iostream> #include <ctime> int main() { std::srand(std::time(0)); //use current time as seed for random generator int uniform_random_variable = std::rand(); std::cout << "Uniform random value on [0 " << RAND_MAX << "]: " << uniform_random_variable << '\n'; }
Posible salida:
Uniform random value on [0 2147483647]: 1373858591
[editar] Ver también
Inicializa un generador de números pseudoaleatorios. (función) | |
Documentación de C de rand
|