1, according to the time to generate m-bit random number, the maximum 13 random number, and can not guarantee that the first is not 0.
Example:
Function Ran (m) {m = m > 13:m; var num = new Date (). GetTime (); return num.tostring (). substring (13-m);} Console.log (Ran (5));
2, according to the random function generated by math to intercept the M-bit, generate random number of the largest not more than 16 bits, can guarantee that the first is not 0.
Example
function rand (m) { m = m > 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));
3, according to math random function generation, the number of digits is not limited, the first is not 0.
Example:
function Rando (m) {var num = '; for (var i = 0; i < m; i++) { var val = parseint (Math.random () *10); if (i = = = 0 && val = = = 0) { i--; Continue;} num + = val;} return num;} Console.log (Rando (5));
JS Generate m-bit random number Getting started instance