C標準ライブラリ提供の擬似乱数生成関数rand
では、既定のシード値は 1 と定義される。
#include <stdlib.h> int main() { // 暗黙にsrand(1)相当でシード値を設定 int x = rand(); }
C11 7.22.2.2/p2より引用(下線部は強調)。
The
srand
function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls torand
. Ifsrand
is then called with the same seed value, the sequence of pseudo-random numbers shall be repeated. If rand is called before any calls tosrand
have been made, the same sequence shall be generated as whensrand
is first called with a seed value of 1.
関連URL