From c751d4eb7940872d9440bcfc635653e09101deb4 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 16 Apr 2022 18:32:17 +0100 Subject: [PATCH] Make sure random numbers are positive --- packages/core/signal.mjs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index cd1083fc..5a0f56f2 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -47,7 +47,7 @@ const timeToIntSeed = (x) => xorwise(Math.trunc(_frac(x / 300) * 536870912)); const intSeedToRand = (x) => (x % 536870912) / 536870912; -const timeToRand = (x) => intSeedToRand(timeToIntSeed(x)); +const timeToRand = (x) => Math.abs(intSeedToRand(timeToIntSeed(x))); const timeToRandsPrime = (seed, n) => { const result = []; @@ -60,8 +60,7 @@ const timeToRandsPrime = (seed, n) => { const timeToRands = (t, n) => timeToRandsPrime(timeToIntSeed(t), n); -export const rand2 = signal(timeToRand); -export const rand = rand2.fmap(Math.abs); +export const rand = signal(timeToRand); export const _brandBy = (p) => rand.fmap((x) => x < p); export const brandBy = (pPat) => reify(pPat).fmap(_brandBy).innerJoin();