Using JS to generate random lottery number list _javascript skills

Source: Internet
Author: User
A friend said his friend shouted questions. Lottery store, want to print out a list.

There are 22 balls numbered 1-22, from which 5 are randomly taken out. Take it out and don't put it back.

For example, the first time I took out is the number 5, the second is from the remaining 21 balls to take. And so on, take 5 balls out altogether.

Take out the last 5 balls, arrange the order regardless, that is to take out is 1 2 3 4 5 and 5 4 3 2 is the same number, print out the list can only come out once

Finally, print out all the results. He called the simple permutation of the problem, involving the array of some operations, I temporarily lost my mind to think.

See if there is a big answer, to provide some more convenient algorithm, thank you very much
<script> var a=[] var b=[] var n for (var i=1;i<23;i++) A.push (i<10? "0" +i:i) for (var i=0;i<5;i++) {n = a.splice (Math.floor (Math.random () * a.length), 1) alert ("Extract: + N") B.pu SH (N)} alert ("Total Extraction:" +b.sort () + "still left:" +a) </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

<script language= "JAVAScript" > Function combination (//full combination MSTR,//source character Mlen//element number) {//Return processing success var vresult = ""; function pcombination (//full combination subroutine Mleft,//arrange to left character mright//align to right character) {if (mleft.length >= mlen) Vresult + = Mleft + "\ n"; else for (var I = 0; I < Mright.length; i++) pcombination (Mleft + mright.substr (i, 1), mright.substr (i + 1, mright.length)); } pcombination ("", MSTR); return vresult; }/* Combination/alert (combination ("12345", 3)); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.