std:: srand
| 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<cstdlib>
|
||
|
void
srand
(
unsigned
seed
)
;
|
||
std::rand()
에서 사용하는 의사 난수 생성기를
seed
값으로 초기화합니다.
만약
std::rand()
가
srand()
를 호출하기 전에 사용되면,
std::rand()
는 마치
srand
(
1
)
로 시드가 설정된 것처럼 동작합니다.
동일한
seed
로
std::rand()
를 시드할 때마다, 동일한 값들의 시퀀스를 생성해야 합니다.
srand()
는 스레드 안전성이 보장되지 않습니다.
목차 |
매개변수
| seed | - | 시드 값 |
반환값
(없음)
참고 사항
일반적으로 말해서, 유사 난수 생성기는 프로그램 시작 시
rand()
를 호출하기 전에 단 한 번만 시드되어야 합니다.
반복적으로 시드하거나 새로운 일괄의 유사 난수를 생성할 때마다 재시드해서는 안 됩니다.
일반적인 관행은 std:: time ( 0 ) 호출 결과를 시드로 사용하는 것입니다. 그러나 std::time 은 std:: time_t 값을 반환하며, std:: time_t 는 정수형으로 보장되지 않습니다. 하지만 실제로는 모든 주요 구현체에서 std:: time_t 를 정수형으로 정의하며, 이는 POSIX에서도 요구하는 사항입니다.
예제
가능한 출력:
Random value on [0, 2147483647]: 1373858591
참고 항목
|
의사 난수를 생성합니다
(함수) |
|
|
std::rand
가 생성할 수 있는 최대값
(매크로 상수) |
|
|
스레드별 난수 엔진을 재시드합니다
(함수) |
|
|
C 문서
for
srand
|
|