魔女帽 庭の隠れ家 竹箒

 乱数を用いた対照実験

作成日 作成日:2025年8月24日

更新日 更新日:2025年8月24日

以下のようにプログラムを書くと、乱数で対照実験ができたりする

#include <iostream>
#include <cstdlib>  // rand, srand
#include <ctime>    // time

using namespace std;

int main() {
	// 乱数の種を現在時刻で初期化
	srand(0);
	
	// 1~100の乱数を10個生成して表示
	for (int i = 0; i < 10; ++i) {
	    int random_number = rand() % 100 + 1; // 1~100の範囲
	    cout << random_number << " ";
	}
	cout << endl;
	srand(0);
	for (int i = 0; i < 10; ++i) {
	    int random_number = rand() % 100 + 1; // 1~100の範囲
	    cout << random_number << " ";
	}
	cout << endl;
	
	return 0;
}