Skip to content

Commit

Permalink
feat: πŸ”₯ Revert rand element logic for now
Browse files Browse the repository at this point in the history
βœ… Closes: #220
  • Loading branch information
theryansmee committed Mar 22, 2022
1 parent 713c77d commit bbe7b0b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 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({ max: clonedData.length - 1 });
const randomIndex = Math.floor(random() * clonedData.length);
const item = clonedData[randomIndex];

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

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

export interface RandomInRangeOptions {
Expand Down

0 comments on commit bbe7b0b

Please sign in to comment.