Home > Article > Web Front-end > JavaScript generates welfare lottery double color ball numbers_javascript skills
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);
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); }
The above is the entire content of this article, I hope you all like it.