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

Class TRandomImpl

packages/effect/src/internal/stm/tRandom.ts:88–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86export const Tag = Context.GenericTag<TRandom.TRandom>("effect/TRandom")
87
88class TRandomImpl implements TRandom.TRandom {
89 readonly [TRandomTypeId]: TRandom.TRandomTypeId = TRandomTypeId
90 constructor(readonly state: TRef.TRef<Random.PCGRandomState>) {
91 this.next = withState(this.state, randomNumber)
92 this.nextBoolean = core.flatMap(this.next, (n) => core.succeed(n > 0.5))
93 this.nextInt = withState(this.state, randomInteger)
94 }
95
96 next: STM.STM<number>
97 nextBoolean: STM.STM<boolean>
98 nextInt: STM.STM<number>
99
100 nextRange(min: number, max: number): STM.STM<number> {
101 return core.flatMap(this.next, (n) => core.succeed((max - min) * n + min))
102 }
103 nextIntBetween(low: number, high: number): STM.STM<number> {
104 return withState(this.state, randomIntegerBetween(low, high))
105 }
106 shuffle<A>(elements: Iterable<A>): STM.STM<Array<A>> {
107 return shuffleWith(elements, (n) => this.nextIntBetween(0, n))
108 }
109}
110
111/** @internal */
112export const live: Layer.Layer<TRandom.TRandom> = Layer.effect(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…