std::rand
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. |
Elemento definito nell'header <cstdlib> | ||
int rand(); | ||
Restituisce un uniformemente distribuiti valore pseudo-casuale integrale tra 0 e
RAND_MAX
(0 e RAND_MAX inclusi).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()
deve essere chiamato prima di qualsiasi chiamata a rand()
per inizializzare il generatore di numeri casuali.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.
Indice |
[modifica]Parametri
(Nessuno)
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.
[modifica]Valore di ritorno
Pseudo-casuale tra valore integrale 0 e
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.
[modifica]Esempio
#include <cstdlib>#include <iostream>#include <ctime> int main(){std::srand(std::time(0));//use current time as seed for random generatorint uniform_random_variable = std::rand();std::cout<<"Uniform random value on [0 "<<RAND_MAX<<"]: "<< uniform_random_variable <<'\n';}
Possible output:
Uniform random value on [0 2147483647]: 1373858591
[modifica]Vedi anche
inizializza pseudo-generatore di numeri casuali 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. (funzione) | |
C documentation for rand |