Skip to content

Commit

Permalink
use Math.random for Hash.random (#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Jun 17, 2024
1 parent 368d735 commit a67b8fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-carrots-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

use Math.random for Hash.random
9 changes: 2 additions & 7 deletions packages/effect/src/Hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<object, number>()
)
/** @internal */
const pcgr = globalValue(
Symbol.for("effect/Hash/pcgr"),
() => new PCGRandom()
)

/**
* @since 2.0.0
Expand Down Expand Up @@ -78,7 +73,7 @@ export const hash: <A>(self: A) => number = <A>(self: A) => {
*/
export const random: <A extends object>(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)!
}
Expand Down

0 comments on commit a67b8fe

Please sign in to comment.