Samples
Address: http://js.zhumimi.cn/zhujiang/index.htm
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> <head> <meta charset="utf8"> <title>Rotary draw</title> <link rel="stylesheet" type="text/css" href="style.css"> <script src="ChouJiang.js"></script> </head> <body> <div> <ul id="choujiang"> <li>1 Yuan Hong Bao</li> <li>2 Yuan Hong Bao</li> <li>3 Yuan Hong Bao</li> <li>4 Yuan Hong Bao</li> <li>666 Yuan Hong Bao</li> <li>Thank you for your coming</li> <li>50 Yuan Hong Bao</li> <li>8 Yuan Hong Bao</li> <li>10 Yuan Hong Bao</li> <li>20 Yuan Hong Bao</li> <li>Thank you for your coming</li> <li>200 Yuan Hong Bao</li> <li>50 Yuan Hong Bao</li> <li>9999 Yuan Hong Bao</li> <li>Thank you for your coming</li> <li>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>