Skip to content

Instantly share code, notes, and snippets.

@urstory
Created September 17, 2015 04:59
Show Gist options
  • Save urstory/04a5eb7ea5791f2071c6 to your computer and use it in GitHub Desktop.
Save urstory/04a5eb7ea5791f2071c6 to your computer and use it in GitHub Desktop.
<!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;
}
// 속성으로 45개 크기의 배열
// 배열은 1 ~ 45 까지의 값을 가지고 있다.
// mix()메소드는 자식의 속성 배열을 섞는다.
// get()메소드는 45개의 배열의 값중 0~5(index)
// 에 해당하는 값을 배열에 담아return
}
var machine =
new LottoMachine();
machine.mix();
var balls = machine.get();
for(var i in balls){
alert(balls[i]);
}
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment