console.log(Math.random());
console.log(Math.random());
function getRandomFloat(min,max) {
return Math.random()*(max - min) + min;
}
console.log(getRandomFloat(5,10));
function getRandomInt(min,max) {
return Math.floor(Math.random()*(max - min) + min);
}
console.log(getRandomInt(5,10));
function getRandomInRange(min,max) {
return Math.floor(Math.random()*(max - min + 1)) + min;
}
console.log(getRandomInRange(1,3));
function coinToss() {
return Math.floor(Math.random() * 2);
}
console.log(coinToss());
function coinToss_t() {
return Math.floor(Math.random() * 2) === 0;
}
console.log(coinToss_t());
var numPool = [5,9,75,54,32,14,25,6];
rand = numPool[Math.floor(Math.random() * numPool.length)];
console.log(rand);
var numPools = [65,32,41,2,7,6,85,32,12,17,26,24];
function shuffle(numPools) {
for (var j,x,i = numPools.length;i;j = parseInt(Math.random() * i),x = numPools[--i],numPools[i] = numPools[j],numPools[j] = x) {
return numPools;
}
}
var randomResult = shuffle(numPools);
while (randomResult.length > 0) {
console.log(randomResult.pop());
}
var cryptoStor = new Uint16Array(8);
var Cryptography = window.crypto.getRandomValues(cryptoStor);
console.log(Cryptography);
学习地址:http://www.htmleaf.com/ziliaoku/qianduanjiaocheng/201612054242.html
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有