MCPcopy
hub / github.com/Effect-TS/effect / _next

Method _next

packages/effect/src/Utils.ts:634–654  ·  view source on GitHub ↗

@internal

()

Source from the content-addressed store, hash-verified

632
633 /** @internal */
634 private _next() {
635 // save current state (what we'll use for this number)
636 const oldHi = this._state[0]! >>> 0
637 const oldLo = this._state[1]! >>> 0
638
639 // churn LCG.
640 mul64(this._state, oldHi, oldLo, MUL_HI, MUL_LO)
641 add64(this._state, this._state[0]!, this._state[1]!, this._state[2]!, this._state[3]!)
642
643 // get least sig. 32 bits of ((oldstate >> 18) ^ oldstate) >> 27
644 let xsHi = oldHi >>> 18
645 let xsLo = ((oldLo >>> 18) | (oldHi << 14)) >>> 0
646 xsHi = (xsHi ^ oldHi) >>> 0
647 xsLo = (xsLo ^ oldLo) >>> 0
648 const xorshifted = ((xsLo >>> 27) | (xsHi << 5)) >>> 0
649 // rotate xorshifted right a random amount, based on the most sig. 5 bits
650 // bits of the old state.
651 const rot = oldHi >>> 27
652 const rot2 = ((-rot >>> 0) & 31) >>> 0
653 return ((xorshifted >>> rot) | (xorshifted << rot2)) >>> 0
654 }
655}
656
657function mul64(

Callers 2

constructorMethod · 0.95
numberMethod · 0.95

Calls 2

mul64Function · 0.85
add64Function · 0.85

Tested by

no test coverage detected