予想というか、ランダム数字排出プログラムです。

404 NOT FOUND | Matsubo Tech Blog
Ruby on Rails, Web Services, Software Development, Startups
ほんと、ただ6桁の数字と、ボーナス数字をはじき出すだけ。
ロト6の当選番号がランダムに選ばれるなら、ランダムに数字をはじいて対抗する!
んでもって、ソースは以下。
表示用 (loto.php)
<html>
<head>
<title>ロト6ランダムピッカー</title>
</head>
<body>
<h1>ロト6の番号をランダムで選びます。</h1>
<?php
include_once('./Rand.php');
# instance
$randum = new Rand(1,42);
# store result
$result = array();
# make 6 randum number
for($i=0; $i<6; $i++){
$tmp = $randum->returnval();
# かぶったらやり直す
while(array_search($tmp, $result)){ $tmp = $randum->returnval(); }
$result[$i] = $tmp;
}
# sort
sort($result);
# print regular number
for($i=0; $i<6; $i++){
print $result[$i]." \n";
}
# make and print bonus number
$tmp = $randum->returnval();
while(array_search($tmp, $result)){ $tmp = $randum->returnval();
print($tmp);
}
?>
</body>
</html>
計算用クラス (Rand.php)
<?php
class Rand{
var $min = 0;
var $max = 100;
function Rand($min, $max){
$this->seed();
$this->min = $min;
$this->max = $max;
}
function setMinMax($min, $max){
$this->min = $min;
$this->max = $max;
}
function seed(){
srand((double) microtime() * 1000000);
usleep(5);
}
function returnval(){
$this->seed();
return rand($this->min, $this->max);
}
}


コメント