# Realization of Js rotary lottery

## Samples

Source code: https://pan.baidu.com/s/15khesfclf1wmoom6pzcja

## II. Implementation method

1: build a circular list

The construction of circular list is mainly for the infinite loop of child nodes

The data structure and algorithm of the circular linked list are introduced here.

2: control the winning probability

How to control the winning probability? I wrote a function to control the generating probability of random numbers: https://www.cnblogs.com/whnba/p/10214312.html

3: control rotation speed

Here is to set a start speed, end speed, step up value to achieve the end of the control program.

4: Example

```<!DOCTYPE html>

<meta charset="utf8">
<title>Rotary draw</title>
<script src="ChouJiang.js"></script>

<body>
<div class="main">
<ul id="choujiang">
<li class="s s1">1 Yuan Hong Bao</li>
<li class="s s2">2 Yuan Hong Bao</li>
<li class="s s3">3 Yuan Hong Bao</li>
<li class="s s4">4 Yuan Hong Bao</li>
<li class="s s5">666 Yuan Hong Bao</li>
<li class="s s6">Thank you for your coming</li>
<li class="s s7">50 Yuan Hong Bao</li>
<li class="s s8">8 Yuan Hong Bao</li>
<li class="s s9">10 Yuan Hong Bao</li>
<li class="s s10">20 Yuan Hong Bao</li>
<li class="s s11">Thank you for your coming</li>
<li class="s s12">200 Yuan Hong Bao</li>
<li class="s s13">50 Yuan Hong Bao</li>
<li class="s s14">9999 Yuan Hong Bao</li>
<li class="s s15">Thank you for your coming</li>
<li class="s s16">88888 Yuan Hong Bao</li>
</ul>
<button id="start" onclick="start()">Start raffle</button>
</div>
<script>
'use strict';
function start() {
let target = new ChouJiang('choujiang', new Map([
[13, 0.0001],   // Set winning probability: [node index, winning rate]
[14, 0.25],
[15, 0.0001],
[10, 0.25],
[5, 0.25],
]));
//target.winning = 4; / / set winning node: used for cheater
target.start();   // start
}
</script>
</body>

</html>
```

Tags: Javascript

Posted on Mon, 02 Dec 2019 04:33:55 -0500 by NL_Rosko