RAND_MAX
From cppreference.net
C++
Numerics library
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (
valarray
)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Pseudo-random number generation
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definiert im Header
<cstdlib>
|
||
|
#define RAND_MAX /*implementierungsdefiniert*/
|
||
Erweitert zu einem ganzzahligen konstanten Ausdruck, der dem maximalen Wert entspricht, der von der Funktion std::rand zurückgegeben wird. Dieser Wert ist implementierungsabhängig. Es ist garantiert, dass dieser Wert mindestens 32767 beträgt.
Beispiel
Diesen Code ausführen
#include <climits> #include <cstdlib> #include <ctime> #include <iostream> int main() { // verwende aktuelle Zeit als Seed für Zufallsgenerator std::srand(std::time(NULL)); std::cout << "RAND_MAX: " << RAND_MAX << '\n' << "INT_MAX: " << INT_MAX << '\n' << "Random value on [0,1]: " << static_cast<double>(std::rand()) / RAND_MAX << '\n'; }
Mögliche Ausgabe:
RAND_MAX: 2147483647 INT_MAX: 2147483647 Random value on [0,1]: 0.618608
Siehe auch
|
erzeugt eine Pseudo-Zufallszahl
(Funktion) |
|
|
initialisiert den Pseudo-Zufallszahlengenerator
(Funktion) |
|
|
C-Dokumentation
für
RAND_MAX
|
|