"JavaScript" randomly generates 10 0~100 numbers

Source: Internet
Author: User

Randomly generates 10 0~100 of non-repeating numbers (including 0 and 100);

Knowledge points to use: random numbers

Go heavy

Put the code below

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "UTF-8">        <title></title>    </Head>    <Body>        <Script>//The definition declares an array, placing randomly generated 10 numbers            vararr= [];  for(varI=0; I<Ten; I++){//rounding contains 0 and                varN=Math.Round (Math.random ()* -);//Detect Duplicates                varoff= false;//assuming random numbers don't repeat.                 for(varJ=0; J<Arr.length; J++){                    if(n==Arr[j]) {//change the state of off if you repeatoff= true;//Jump out of the current code block                         Break; }                }//determine the status of off                if(off) {i--                }Else{Arr.push (n); }            }        </Script>    </Body></HTML>

Write code before the idea must be clear, tidy up logic and then write will make your development more effective!

"JavaScript" randomly generates 10 0~100 numbers

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.