Skip to content

Commit

Permalink
feat: πŸ”₯ Replace use of random index logic with getRandomInRange
Browse files Browse the repository at this point in the history
βœ… Closes: #220
  • Loading branch information
theryansmee committed Mar 22, 2022
1 parent 6b57aa0 commit 713c77d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/falso/src/lib/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function fakeFromArray<T, Options extends FakeOptions>(
const newArray: T[] = [];

while (clonedData.length && newArray.length !== options.length) {
const randomIndex = getRandomInRange({ min: clonedData.length });
const randomIndex = getRandomInRange({ max: clonedData.length - 1 });
const item = clonedData[randomIndex];

newArray.push(item);
Expand All @@ -85,7 +85,8 @@ export function fakeFromArray<T, Options extends FakeOptions>(
}

export function randElement<T>(arr: T[]): T {
return arr[Math.floor(random() * arr.length)];
const randomIndex = getRandomInRange({ max: arr.length - 1 });
return arr[randomIndex];
}

export interface RandomInRangeOptions {
Expand Down

0 comments on commit 713c77d

Please sign in to comment.