std::rand – cppreference.com
Aus cppreference.com
<metanoindex/>
<tbody> </tbody>
| definiert in Header <cstdlib> |
||
|
|
||
Gibt eine gleichmäßig verteilte pseudo-zufälligen ganzzahligen Wert zwischen 0 und RAND_MAX (0 und RAND_MAX enthalten) .
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.
srand() sollte aufgerufen werden, bevor irgendwelche Anrufe zu rand() den Zufallszahlengenerator zu initialisieren werden .
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.
Parameter
(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Rückgabewert
Pseudo-Random-ganzzahligen Wert zwischen 0 und 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.
Beispiel
#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'; }
Possible output:
Uniform random value on [0 2147483647]: 1373858591
Siehe auch
initialisiert Pseudo-Zufallszahlengenerator Original: initializes pseudo-random number generator The text has been machine-translated via Google Translate. (Funktion) [edit] | |