웹스쿨

로또 시뮬레이션을 제작했다. 본문

일상

로또 시뮬레이션을 제작했다.

마스터욱 2023. 3. 30. 01:48
반응형

제작을 한 계기는 단순하다.

- 자동으로 얼마치를 해야만 1등이 걸릴까?

- 평균 회수비용은 몇%일까?

- 로또는 정말 내 인생의 희망이 될 수 있을까?

 

결과는 참담했다.

10억치를 해도 1등이 걸리지 않았다 ㅜㅜ;

더욱더 지치게 하는건 10억치를 자동으로 돌리는데 반나절이 걸렸다는 거다...

 

머 잡다한 말은 집어치우고

소스를 공개합니다.

전 오픈 마인드 개발자이기 때문에 100% 소스를 오픈합니다.

 

아직 회수금액 계산루틴을 넣지 않았지만 대략적으로 때려보니 20% 정도이다.

즉 100만원 로또하면 20만원 회수된다 이말이다.

 

다음 버전으로 회수금액 계산공식을 넣어서 얼마,몇% 회수했는지에 대한 정보도 표기할 예정이다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
 
    $today_lotto = "5 10 13 27 37 41 4";
 
?>
 
<style type="text/css">
    .lotto_div { display:inline-block;margin:5px;width:30px;height:30px;line-height:30px; }
    .lotto_div_list { display:inline-block;margin:5px;width:30px;height:30px;line-height:30px; }
</style>
 
<script type="text/javascript">
 
    var Lotto = {
        "TodayLotto"    : "<?=$today_lotto?>".split(" "),
        "LottoRoof"        : 0,
        "LottoRoofCnt"    : 0,
        "LottoTimeOut"    : null,
 
        "LottoGo" : function(Cnt) {
            if ( this.LottoTimeOut != null ) {
                alert("시뮬레이션 중입니다....");
                return;
            }
 
            this.LottoRoof = Cnt;
            if ( confirm(number_format(Cnt / 10+ "만원 시뮬레이션을 하시겠습니까?") ) {
                $("#ResultBox").show(500);
 
                for ( var i = 1; i <= 5; i++ ) { // 1등부터 5등까지
                    $("#Lotto_" + i).val(0);
                    $("#LottoList_" + i).html("");
                }
 
                this.LottoTimeOut = setInterval("Lotto.LottoProc()"10);
            }
        },
 
        "LottoProc" : function() {
            this.LottoRoofCnt++;
            if ( this.LottoRoofCnt > this.LottoRoof ) {
                console.log("스톱");
                clearTimeout(this.LottoTimeOut);
                this.LottoTimeOut = null;
                this.LottoRoofCnt = 0;
                this.LottoRoof = 0;
                alert("시뮬레이션이 종료되었습니다.");
                return;
            }
 
            var LottoArray = this.LottoGet();
            var LottoString = "";
            var LottoOk = 0;
            var LottoBonus = false;
            var Len = this.TodayLotto.length - 1;
            for ( var key in LottoArray ) {
                var BgColor = "black";
                for ( var i = 0; i < Len; i++ ) {
                    if ( this.TodayLotto[i] == LottoArray[key] ) {
                        LottoOk++;
                        BgColor = "green";
                        break;
                    }
                }
 
                if ( LottoArray[key] == this.TodayLotto[this.TodayLotto.length - 1] ) { // 보너스 번호
                    LottoBonus = true;
                }
 
                LottoString += "<div class='w3-circle lotto_div' style='color:#FFF;background-color:"+BgColor+";'>" + LottoArray[key] + "</div>";
            }
            LottoString = "<div>" + LottoString + "</div>";
            console.log(this.LottoRoofCnt + "번째 시도 : " + LottoOk);
 
            var LottoRank = null;
            switch ( LottoOk ) {
                case :
                    LottoRank = 5break;
                case :
                    LottoRank = 4break;
                case :
                    LottoRank = LottoBonus ? 3break;
                case :
                    LottoRank = 1break;
            }
 
            $("#LottoBox").html(LottoString);
            if ( LottoRank != null ) {
                $("#Lotto_" + LottoRank).val(parseInt($("#Lotto_" + LottoRank).val()) + 1);
                $("#LottoList_" + LottoRank).html(LottoString.replace(/lotto_div/gi, "lotto_div_list"+ $("#LottoList_" + LottoRank).html());
            }
 
            var String = "";
            String += number_format(this.LottoRoof) + " 회중 ";
            String += number_format(this.LottoRoofCnt) + " 회 진행중<br>";
            String += "진행률 = " + Math.round(this.LottoRoofCnt / this.LottoRoof * 100+ "%<br>";
            String += "결제금액 = " + number_format(this.LottoRoofCnt * 1000+ "원";
            $("#LottoBoxCount").html(String);
        },
 
        "LottoGet" : function() {
            var Lotto = new Array();
            var Count = 0;
            while ( Count < ) {
                var Flag = true;
                var Number = parseInt( Math.random() * 45 + 1;
                for ( var i = 0; i < Count; i++ ) {
                    if ( Lotto[i] == Number ) {
                        Flag = false;
                        break;
                    }
                }
 
                if ( Flag ) {
                    Lotto[Count] = Number;
                    Count++;
                }
            }
 
            return Lotto;
        }
    };
 
</script>
 
<div style="text-align:center;min-height:100%;height:auto !important;height:100%;">
    <div class="w3-panel w3-pale-green w3-leftbar w3-border-green">
        <p></p>
        <p class="w3-xlarge w3-serif">
            <i>"버그 없습니다. 의심좀 하지 마세요 T^T"</i>
        </p>
        <p>진짜 확률이 이래요!</p>
    </div>
    <div class="w3-panel w3-pale-green">
        <h3>지난주 로또 번호</h3>
        <p>돈 없으면 가상으로라도 때려보자!</p>
        <?php
            $LottoArray = explode(" ", $today_lotto);
            foreach ( $LottoArray as $key => $number ) {
                if ( $key == ) {
                    echo "<div style='display:inline-block;margin:5px;font-size:20px;font-weight:bold;'> + </div>";
                }
 
                echo "<div class='w3-circle w3-indigo lotto_div'>".$number."</div>";
            }
        ?>
    </div>
    <div style="margin-top:30px;">
        <div style="margin-top:10px;">
            <input type="button" class="w3-btn black" style="font-size:13px;" value="10만원" onclick="Lotto.LottoGo('100');">
            <input type="button" class="w3-btn black" style="font-size:13px;" value="100만원" onclick="Lotto.LottoGo('1000');">
            <input type="button" class="w3-btn black" style="font-size:13px;" value="1,000만원" onclick="Lotto.LottoGo('10000');">
            <input type="button" class="w3-btn black" style="font-size:13px;" value="1억원" onclick="Lotto.LottoGo('100000');">
        </div>
    </div>
    <div id="ResultBox" xstyle="display:none;">
        <div style="margin-top:30px;" id="LottoBox_score">
            <hr>
            <table align="center" style="width:100%;">
            <tr>
                <td><input type="button" class="w3-btn w3-dark-gray" value="1등" style="width:99%;" /></td>
                <td><input type="button" class="w3-btn w3-dark-gray" value="2등" style="width:99%;" /></td>
                <td><input type="button" class="w3-btn w3-dark-gray" value="3등" style="width:99%;" /></td>
                <td><input type="button" class="w3-btn w3-dark-gray" value="4등" style="width:99%;" /></td>
                <td><input type="button" class="w3-btn w3-dark-gray" value="5등" style="width:99%;" /></td>
            </tr>
            <tr>
                <td><input type="button" class="w3-btn" value="0" style="width:99%;font-weight:bold;font-size:18px;" id="Lotto_1" /></td>
                <td><input type="button" class="w3-btn" value="0" style="width:99%;font-weight:bold;font-size:18px;" id="Lotto_2" /></td>
                <td><input type="button" class="w3-btn" value="0" style="width:99%;font-weight:bold;font-size:18px;" id="Lotto_3" /></td>
                <td><input type="button" class="w3-btn" value="0" style="width:99%;font-weight:bold;font-size:18px;" id="Lotto_4" /></td>
                <td><input type="button" class="w3-btn" value="0" style="width:99%;font-weight:bold;font-size:18px;" id="Lotto_5" /></td>
            </tr>
            </table>
        </div>
        <div style="margin-top:30px;font-weight:bold;font-size:18px;" id="LottoBoxCount"></div>
        <div style="margin-top:30px;" id="LottoBox"></div>
        <div>
            <?php
            for($i = 5; $i >= 1; $i--){
                if($i == || $i == 3){
                    echo "<div class='row'>";
                }
            ?>
                <div class="col-md-<?php if($i >= 4){echo "6";}else{echo "4";} ?>" style="padding-left:1px;padding-right:1px;margin-bottom:10px;">
                    <div class="w3-pale-green w3-bottombar w3-border-green w3-border">
                        <p style="margin:5px 0px;"><?=$i?>등 리스트</p>
                    </div>
                    <div id="LottoList_<?=$i?>" style="min-height:100px;max-height:500px;overflow-y:auto;border:1px solid #4CAF50;"></div>
                </div>
            <?php
                if($i == || $i == 1){
                    echo "</div>";
                }
            }
            ?>
        </div>
    </div>
</div>
cs

 

 

 

 


이 게시글은
https://webschool.kr/?v=board_view&board_key=4&idx=13
에서 작성한 글입니다. 소스코드의 경우 해당 블로그에서 이뿌게 노출이 되지 않을 수 있사오니, 위 링크로 들어오셔서 보시길 바랍니다.

반응형