std::rand
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 <cstdlib>
|
||
int rand(); |
||
Retourne une répartie uniformément pseudo-aléatoire valeur entière comprise entre 0 et
RAND_MAX
(0 et RAND_MAX comprises) .Original:
Returns a uniformly distributed pseudo-random integral value between 0 and
RAND_MAX
(0 and RAND_MAX included).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.
srand()
doit être appelée avant tout appel à rand()
pour initialiser le générateur de nombres aléatoires .Original:
srand()
should be called before any calls to rand()
to initialize the random number generator.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.
Sommaire |
[modifier] Paramètres
(Aucun)
Original:
(none)
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.
[modifier] Retourne la valeur
Pseudo-aléatoire valeur entière comprise entre 0 et
RAND_MAX
.Original:
Pseudo-random integral value between 0 and
RAND_MAX
.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.
[modifier] Exemple
#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'; }
Résultat possible :
Uniform random value on [0 2147483647]: 1373858591
[modifier] Voir aussi
initialise générateur de nombre pseudo-aléatoire Original: initializes pseudo-random number generator The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction) | |
C documentation for rand
|