概要
PHPのコードを書いてみたので載せておきます。
宝くじが好きでよく買うので、ロトシックスを買った時の当たる回数を1万回したときにどうなるか試してみました。
ただ、ランダムで選択すると思った関数が、そこまでランダムでなく規則性があったので、変えていきたいとは思います。
※デバッグ用のものはわざと残しています。
※選択する数字やミニロト、ロトシックス、ロトセブンは一つのコードだけですべて行えるかもですが、まずはロトシックスのみを行っています。
作成したコード
<?php //1等から5等までが10000回中何回当たったか調べるコード //★★ランダムが偏りすぎていいものを探して使う //自分の数を決定 今回はコード内で決めるが、決めてもらうように修正する $select_num = array(10,13,26,38,41,43); //全選択値の配列を作成 $all_number = array(); for($i = 1; $i < 44; $i++ ){ $all_number[] = $i; } $all_count = 0; $numbers = array('5等' => 0 , '4等' => 0 ,'3等' => 0 ,'2等' => 0 , '1等' => 0); $judge = true; while($judge){ //ランダムで数字選択 $select_randam = array_rand($all_number, 6); $plus = 0; foreach($select_randam as $select_randam_plus){ $select_randam[$plus] = ++$select_randam_plus; $plus++; } // print_r($select_randam); echo '<br>';exit; $judge_etc = true; while($judge_etc){ $select_etc = array_rand($all_number, 1); $key = in_array($select_etc, $select_randam); if ($key){ continue; }else{ $judge_etc = false; } } // print_r($select_randam); echo '<br>'; // print_r($select_etc); // print_r($select_num);exit; //キー内の値をソート // $sort_number = // sort($select_randam); $count = 0; //順番に一致しているか判定 for($i = 0; $i < 6; $i++) { for($j = 0; $j < 6; $j++){ if($select_num[$i] === $select_randam[$j]){ $count++; } } } //ここに2等の他の値が含まれるか調べるコードを足す if($count == 5){ foreach($select_num as $select_value){ if($select_value == select_etc){ $count = 7; } } } switch ($count) { case 3: $numbers['5等']++; break; case 4: $numbers['4等']++; break; case 5: $numbers['3等']++; break; case 7: $numbers['2等']++; break; case 6: $numbers['1等']++; break; } $all_count++; //1万回に到達すると終了する if($all_count == 10000){ break; } } //var_dump($numbers); echo 'あなたの選んだ数字は、1万回中'; foreach($numbers as $key => $value){ echo $key. 'が' . $value .'回、' ; } echo '当たりました'; ?>