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
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<cstdlib>
|
||
|
#define RAND_MAX /*implementation defined*/
|
||
std::rand 함수가 반환할 수 있는 최대값과 동일한 정수 상수 표현식으로 확장됩니다. 이 값은 구현에 따라 다릅니다. 이 값이 최소 32767 이상임이 보장됩니다.
예제
이 코드 실행
#include <climits> #include <cstdlib> #include <ctime> #include <iostream> int main() { // 현재 시간을 난수 생성기 시드로 사용 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'; }
가능한 출력:
RAND_MAX: 2147483647 INT_MAX: 2147483647 Random value on [0,1]: 0.618608
참고 항목
|
의사 난수를 생성합니다
(함수) |
|
|
의사 난수 생성기를 시드합니다
(함수) |
|
|
C 문서
for
RAND_MAX
|
|