@2node/random 中文文档教程

发布于 5年前 浏览 26 更新于 3年前

console.log(random(['win', 'mac', 'lin'], [70, 20, 10]));  // random 70% - 'win', 20% - 'mac', 10% - 'lin'
console.log(random(['win', 'mac', 'lin'], [2, 1, 1]));  // random 50% - 'win', 25% - 'mac', 25% - 'lin'
console.log(random(['win', 'mac', 'lin'], [.9, .05, .05]));  // random 50% - 'win', 25% - 'mac', 25% - 'lin'
console.log(random(true));  // random true or false
console.log(random(false));  // random true or false
console.log(random(1));  // random 0 or 1
console.log(random(1.999));  // random 0 or 1 or 2
console.log(random([0, 1, 2, 3]));  // random 0 or 1 or 2 or 3
console.log(random(['a', 'b']));  // random 'a' or 'b'
console.log(random(1, 2));  // random 1 or 2
console.log(random(1, 4));  // random 1 or 2 or 3 or 4
console.log(random(['win', 'mac', 'lin'], [70, 20, 10]));  // random 70% - 'win', 20% - 'mac', 10% - 'lin'
console.log(random(['win', 'mac', 'lin'], [2, 1, 1]));  // random 50% - 'win', 25% - 'mac', 25% - 'lin'
console.log(random(['win', 'mac', 'lin'], [.9, .05, .05]));  // random 50% - 'win', 25% - 'mac', 25% - 'lin'
console.log(random(true));  // random true or false
console.log(random(false));  // random true or false
console.log(random(1));  // random 0 or 1
console.log(random(1.999));  // random 0 or 1 or 2
console.log(random([0, 1, 2, 3]));  // random 0 or 1 or 2 or 3
console.log(random(['a', 'b']));  // random 'a' or 'b'
console.log(random(1, 2));  // random 1 or 2
console.log(random(1, 4));  // random 1 or 2 or 3 or 4
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文