UNPKG

@ededejr/randomly

Version:

A utility for generating random numbers very frequently.

1 lines 872 B
var t=class{constructor(t={}){this.cursor=0,this.store=new Array(t.storeSize||20).fill(void 0).map((()=>Math.random())),this.interval=t.refreshInterval||1e3,this.startTimer()}get(){return this.$get()}compare(t){return t(this.$get())}lt(t){return this.$get()<t}gt(t){return this.$get()>t}between(t,r){const e=this.$get();return e>t&&e<r}decide(t,r,e){const s=e||Math.min(Math.max(this.$get(),.05),.95);return this.$get()>s?t:r}sample(t){return Math.floor(this.$get()*t)}startTimer(){this.randomizeStore(),this.stopTimer(),this.timerId=setTimeout((()=>this.startTimer()),this.interval)}stopTimer(){this.timerId&&clearTimeout(this.timerId)}randomizeStore(){this.store&&(this.store=this.store.map((()=>Math.random())))}$get(){const t=this.store[this.cursor++];return this.cursor===this.store.length&&(this.cursor=0),t}};export{t as Randomly};//# sourceMappingURL=index.mjs.map