theyadev/random-api

View on GitHub
src/utils/getRandom.ts

Summary

Maintainability
A
0 mins
Test Coverage
export default function getRandom<Type>(items: Type[], nb: number): Type[] {
  const randomItems = items.sort(() => {
    return Math.random() - 0.5;
  });

  const randomItem = randomItems.splice(0, nb);

  return randomItem;
}