標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
ISO C |
両方 |
#include <stdlib.h>
int rand(void);
0 ~ RAND_MAX の範囲の疑似乱数整数を生成します。rand() を呼び出して乱数生成プログラムに seed を設定する前には、srand() 関数を 使用してください。srand() を呼び出さない場合、デフォルトのシードは 1 です。
計算値を戻します。
⁄* CELEBR02
This example prints the first 10 random numbers generated.
*⁄
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int x;
for (x = 1; x <= 10; x++)
printf("iteration %d, rand=%d¥n", x, rand());
}
iteration 1, rand=16838
iteration 2, rand=5758
iteration 3, rand=10113
iteration 4, rand=17515
iteration 5, rand=31051
iteration 6, rand=5627
iteration 7, rand=23010
iteration 8, rand=7419
iteration 9, rand=16212
iteration 10, rand=4086