Home >Web Front-end >JS Tutorial >Sharing of 4 functions for generating random numbers implemented in JS_Basic knowledge
The first method
The second method
function NewGuid() {
Return (S4() S4() "-" S4() "-" S4() "-" S4() "-" S4() S4() S4());
}
The third method
The fourth method
function getBetweenRound(min,max){
return Math.floor(min Math.random()*(max-min));
};
function getCharCode(){
for(var i=0,len=3;i
for(var j=thisArr[0],thisLen=thisArr[1];j<=thisLen;j ){
charCodeArr.push(j);
}
}
}
function ranStr(slen){
slen = slen || 20;
charCodeArr.length<62 && getCharCode();
var res = [];
for(var i=0;i
res.push(String.fromCharCode(charCodeArr[index]));
}
return res.join('');
};
this.ranStr = ranStr;
})();