@ededejr/randomly
Version:
A utility for generating random numbers very frequently.
1 lines • 1.28 kB
JavaScript
var t,e=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,o={};((t,r)=>{for(var s in r)e(t,s,{get:r[s],enumerable:!0})})(o,{Randomly:()=>h}),module.exports=(t=o,((t,o,h,n)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let a of s(o))i.call(t,a)||a===h||e(t,a,{get:()=>o[a],enumerable:!(n=r(o,a))||n.enumerable});return t})(e({},"__esModule",{value:!0}),t));var h=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,e){const r=this.$get();return r>t&&r<e}decide(t,e,r){const s=r||Math.min(Math.max(this.$get(),.05),.95);return this.$get()>s?t:e}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}};//# sourceMappingURL=index.js.map