1, JS implementation randomly selected [10,100) in the 10 integers, stored in an array, and sorted.
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Document</title>6 </Head>7 <Body>8 <Scripttype= "Text/javascript">9 Ten functionSortnumber (A, b) { One returna-b;//Ascending A //return b-a;//Descending - } - the varIArray=[]; - functionGetrandom (istart,iend) { - varIchoice=IStart-iend; - returnMath.Abs (Math.ceil (Math.random ()*ichoice))+IStart; The Ceil () method rounds up a number. + } - for(varI=0; I<Ten; I++){ + Iarray.push (Getrandom (Ten, -)) A } at Iarray.sort (sortnumber); - alert (IArray) - </Script> - </Body> - </HTML>
The following two questions only need to replace the getrandom () function in the code above.
2, JS implementation randomly selected (10,100] in 10 integers, stored in an array, and sorted.
1 function Getrandom (istart,iend) {2 var ichoice = istart-iend; 3 return Math.Abs (Math.floor (Math.random () *ichoice)) +istart; The floor () method can be rounded down by a number. 4 }
3, JS implementation randomly selected [10,100] in 10 integers, stored in an array, and sorted.
1 function Getrandom (istart,iend) {2 var ichoice = istart-iend-1; 3 return Math.Abs (Math.ceil (Math.random () *ichoice)) +istart; 4 }
The
JS implementation randomly selects the 10 integers in [10,100], deposits an array, and sorts. Also consider (10,100] and [10,100] two cases.