Javascript generates a random m-bit number based on the time. The maximum random number is 13 digits, and the first digit cannot be zero. The implementation code is as follows. If you need a friend, refer to generate a random m-bit number based on time, the maximum random number is 13 digits, and the first digit cannot be zero.
Function ran (m) {m = m> 13? 13: m; var num = new Date (). getTime (); return num. toString (). substring (13-m);} console. log (ran (5 ));
Based on the random number generated by the random function of Math, the random number is intercepted by m bits. the maximum number of random numbers generated cannot exceed 16 bits, and the first digit cannot be 0.
Function rand (m) {m = m> 16? 16: m; var num = Math. random (). toString (); if (num. substr (num. length-m, 1) ==='0') {return rand (m);} return num. substring (num. length-m);} console. log (rand (5 ));
Generated Based on the random function of Math. There is no limit on the number of digits and the first digit is not 0.
Function rando (m) {var num = ''; for (var I = 0; I <m; I ++) {var val = parseInt (Math. random () * 10, 10); if (I = 0 & val = 0) {I --; continue;} num + = val ;} return num;} console. log (rando (5 ));