From bbe7b0b6a645c53e4f27f1e001bf4c02455e125d Mon Sep 17 00:00:00 2001 From: Ryan Smee Date: Tue, 22 Mar 2022 19:19:40 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=94=A5=20Revert=20rand=20element?= =?UTF-8?q?=20logic=20for=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #220 --- packages/falso/src/lib/core/core.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/falso/src/lib/core/core.ts b/packages/falso/src/lib/core/core.ts index d03c3bdbd..b3d9a8ca3 100644 --- a/packages/falso/src/lib/core/core.ts +++ b/packages/falso/src/lib/core/core.ts @@ -74,7 +74,7 @@ export function fakeFromArray( const newArray: T[] = []; while (clonedData.length && newArray.length !== options.length) { - const randomIndex = getRandomInRange({ max: clonedData.length - 1 }); + const randomIndex = Math.floor(random() * clonedData.length); const item = clonedData[randomIndex]; newArray.push(item); @@ -85,8 +85,7 @@ export function fakeFromArray( } export function randElement(arr: T[]): T { - const randomIndex = getRandomInRange({ max: arr.length - 1 }); - return arr[randomIndex]; + return arr[Math.floor(random() * arr.length)]; } export interface RandomInRangeOptions {