From a67b8fe2ace08419424811b5f0d9a5378eaea352 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 18 Jun 2024 00:25:39 +1200 Subject: [PATCH] use Math.random for Hash.random (#3001) --- .changeset/short-carrots-confess.md | 5 +++++ packages/effect/src/Hash.ts | 9 ++------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 .changeset/short-carrots-confess.md diff --git a/.changeset/short-carrots-confess.md b/.changeset/short-carrots-confess.md new file mode 100644 index 0000000000..793883d450 --- /dev/null +++ b/.changeset/short-carrots-confess.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +use Math.random for Hash.random diff --git a/packages/effect/src/Hash.ts b/packages/effect/src/Hash.ts index 67617135ad..c0bfed746b 100644 --- a/packages/effect/src/Hash.ts +++ b/packages/effect/src/Hash.ts @@ -4,18 +4,13 @@ import { pipe } from "./Function.js" import { globalValue } from "./GlobalValue.js" import { hasProperty } from "./Predicate.js" -import { PCGRandom, structuralRegionState } from "./Utils.js" +import { structuralRegionState } from "./Utils.js" /** @internal */ const randomHashCache = globalValue( Symbol.for("effect/Hash/randomHashCache"), () => new WeakMap() ) -/** @internal */ -const pcgr = globalValue( - Symbol.for("effect/Hash/pcgr"), - () => new PCGRandom() -) /** * @since 2.0.0 @@ -78,7 +73,7 @@ export const hash: (self: A) => number = (self: A) => { */ export const random: (self: A) => number = (self) => { if (!randomHashCache.has(self)) { - randomHashCache.set(self, number(pcgr.integer(Number.MAX_SAFE_INTEGER))) + randomHashCache.set(self, number(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER))) } return randomHashCache.get(self)! }