1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 4 <Head>5 <MetaCharSet= "UTF-8">6 <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0">7 <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge">8 <title>Document</title>9 </Head>Ten One <Body> A - </Body> - <Script> the var Times= 100000; - varRes= {}; - - for (varI= 0; I<Times ; I++) { + vararr=Shuffle ([1, 2, 3]); - + varKey=json.stringify (arr); A Res[key]?Res[key]++: Res[key]= 1; at } - - //for easy display, convert to percent - for (varKeyinchRes) { - Res[key]=Res[key]/ Times* - + '%' - } in - //ES5 to functionShuffle (a) { + varJ, X, I; - for(i=a.length; i; I--) { the J=Math.floor (Math.random ()*i); * x=A[i- 1]; $ A[i- 1] =A[j];Panax Notoginseng A[j]=x; - } the returnA; + } A the + //ES6 - functionShuffle (a) { $ for(Let I=a.length; i; I--) { $ Let J=Math.floor (Math.random ()*i); - [A[i- 1], A[j]]=[A[j], A[i- 1]]; - } the returnA; - }Wuyi the Console.log (RES) - </Script> Wu - About </HTML>
JS Random code Chaos ordinal Group