js get random n items from array code example
Example 1: get random entry from array javascript
const rnd = (arr) => { return arr[Math.floor(Math.random() * arr.length)] };
Example 2: javascript get n random elements from array
// Shuffle array
const shuffled = array.sort(() => 0.5 - Math.random());
// Get sub-array of first n elements after shuffled
let selected = shuffled.slice(0, n);