原生JS随机数

// 获取从 1 到 10 的随机整数,取 0 的概率极小。
Math.ceil(Math.random()*10);
 
// 可均衡获取 0 到 1 的随机整数。
Math.round(Math.random());
 
// 可均衡获取 0 到 9 的随机整数。
Math.floor(Math.random()*10);
 
// 基本均衡获取 0 到 10 的随机整数,其中获取最小值 0 和最大值 10 的几率少一半。
Math.round(Math.random()*10);
 
使用场景:
一般对于post请求或者接口请求,最好是加个随机数,以免页面缓存导致数据不准确

但行好事,莫问前程!

本文来自博客园,作者:yangphp,转载请注明原文链接:https://www.cnblogs.com/ypeih/p/15391267.html

原文地址:https://www.cnblogs.com/ypeih/p/15391267.html