Generate m-bit random numbers based on time, with a maximum of 13-bit random numbers, and it cannot be guaranteed that the first bit is not 0
function ran(m) {m = m > 13 ? 13 : m;var num = new Date().getTime(); return num.toString().substring(13 - m);}console.log(ran(5));The random number generated by Math's random function intercepts m bits. The generated random number shall not exceed 16 bits, which ensures that the first bit is not 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 according to Math's random function, there is no limit on the number of digits, the first digit is not 0
function random(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));