Skip to content

Instantly share code, notes, and snippets.

@urstory
Last active September 18, 2015 02:03
Show Gist options
  • Save urstory/ed5b7b1786203fc30c51 to your computer and use it in GitHub Desktop.
Save urstory/ed5b7b1786203fc30c51 to your computer and use it in GitHub Desktop.
lotto.html
<!DOCTYPE html>
<html>
<head>
<script>
function LottoMachine(){
this.balls = Array(45);
this.mix = function(){
for(var i = 0; i < 45; i++){
this.balls[i] = i+1;
}
for(var i = 0; i < 10000; i++){
var index1 =
parseInt(Math.random() * 45);
var index2 =
parseInt(Math.random() * 45);
if(index1 != index2){
var tmp = this.balls[index1];
this.balls[index1] =
this.balls[index2];
this.balls[index2] = tmp;
}
}
}
this.get = function(){
var result = Array(6);
for(var i = 0; i < 6; i++){
result[i] = this.balls[i];
}
return result;
}
}
window.onload = function(){
var machine =
new LottoMachine();
machine.mix();
var balls = machine.get();
for(var i in balls){
var boxId = 'box' + (parseInt(i)+1);
// console.log(boxId);
var divBox = document.getElementById(boxId);
// console.log(divBox);
divBox.innerHTML = "<div class='lottoNumber'>" + balls[i] + "</div>";
}
}
</script>
<style type="text/css">
.box {
text-align:center;
font-size: 50px;
}
.lottoNumber {
width:50px;
height:50px;
padding-top: 80px;
padding-left: 80px;
}
#box1 { width:200px; height:200px; background-color:#438eb9; float:left; }
#box2 { width:200px; height:200px; background-color:#629b58; float:left; }
#box3 { width:200px; height:200px; background-color:#e59729; float:left; }
#box4 { width:200px; height:200px; background-color:#90a050; float:left; }
#box5 { width:200px; height:200px; background-color:#889074; float:left; }
#box6 { width:200px; height:200px; background-color:#b490c0; float:left; }
</style>
</head>
<body>
<div class="box" id="box1"></div>
<div class="box" id="box2"></div>
<div class="box" id="box3"></div>
<div class="box" id="box4"></div>
<div class="box" id="box5"></div>
<div class="box" id="box6"></div>
</body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment