Home > Web Front-end > JS Tutorial > JavaScript generates welfare lottery double color ball numbers_javascript skills

JavaScript generates welfare lottery double color ball numbers_javascript skills

WBOY
Release: 2016-05-16 15:58:57
Original
2376 people have browsed it

The double-color ball numbers of the welfare lottery are composed of 6 red ball numbers and 1 basketball number. Among them, the 6 red ball numbers are 6 numbers randomly drawn from 01 to 33, and the 1 basketball number is from 01 to a randomly selected number out of 16. The 6 red ball numbers are usually arranged in order from small to large. The following is a method to generate a double-color ball number in JavaScript for your reference!

var redBall = new Array();
var redLen = redBall.length;
while(redLen<6){
 var ball = ranNumber(1,33);
 var flag = true;
 for(var j=0;j<redLen;j++){
 if(redBall[j]==ball){
   flag = false;
   break;
  }
 }
 
 if(flag){
  if(ball<10){
   redBall.push(“0″+ball);
  }else{
   redBall.push(ball);
  }
 }
 
 redLen = redBall.length;
}
redBall.sort();
var blueBall = ranNumber(1,16);
if(blueBall<10){
 blueBall = “0″+blueBall;
}
alert(redBall.join(‘,') + “|” + blueBall);

Copy after login

The following is the ranNumber method, which randomly returns an integer between s and e.

function ranNumber(s,e){
 var staVal = parseFloat(s);
 var endVal = parseFloat(e);
 return Math.floor(Math.random()*(endVal-staVal)+staVal);
}

Copy after login

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template