用户:yee剑走天下查看:331 回复:8 评论:10 创建时间:2022-11-10T14:28:13
python里面()
有random.randint(好像是这样拼?)
但是JS里面,只给了你一个Math.random()
然后我就花了20秒写了个ljljljljljlj不能再lj的随机数函数()(
Math.randint = function(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
又氵了一个帖子))))
浮生awa这样化简到一行岂不美哉,而且更有b格
还可以加个函数注释,显得更加nb(什
/**
* @param {Number} min 随机生成数的最小值
* @param {Number} max 随机生成数的最大值
*/
Math.randint = (min, max) => Math.floor(Math.random() * (max - min + 1) + min)
硬是把简单的代码写成了萌新看不懂的样子(bushi
点赞0
评论
屑()要用class类来实现面向对象编程概念才会让萌新看不懂()()看我置顶的评论()
究极繁化版()())()
console.clear()
class random {
constructor(min, max) {
this.min = min;
this.max = max;
this.PI = Math.PI
this.poor = () => this.max > this.min ? ((this.max - this.min) * Math.PI / ((this.PI / Math.PI) * this.PI)) | 0 : ((this.min - this.max) * Math.PI / ((this.PI / Math.PI) * this.PI)) | 0
}
randint() {
return Math.floor(
Math.random() * (this.poor() + this.min)
)
}
};
class Random extends random {
constructor(min, max) {
super(min, max);
this.log = console.log;
}
randint() {
return super.randint()
}
};
globalThis.Random = Random;
var test = new Random(10, 100).randint();
console.log(test)点赞1
评论
真无语
yeeeeee~
(this.PI / Math.PI) emm
都说了是繁化啊()()
你信不信我能做出不用Math的随机()()()
点赞0
评论
不可能()绝对不可能()
new Date 和 toFixed 是个好东西()()
你试试(其实是一个伪随机)
new Date不是日期吗()管随机数什么事)
var randomNum = (function(){
var today = new Date();
var seed = today.getTime();
function rnd(){
seed = ( seed * 9301 + 49297 ) % 233280;
return seed / ( 233280.0 );
};
return function rand(number){
return Math.ceil(rnd(seed) * number);
};
})();
线性同源生成器随机数,不用random(其实是把random的底层逻辑弄出来了)使用方法:
console.log(randomNum(100))点赞0
评论