JSFiddle - React, Tailwind, and code Playground

by jonathon

JavaScript

var arr = [], // acceptable values
    randomArray = []; // random array

// Create an array of numbers 0 to 45;
for(var i=1; i <=45 ; i++){
  arr.push(i);   
}

// From http://stackoverflow.com/q/962802#962890
function shuffle(array) {
    var tmp, current, top = array.length;

    if(top) while(--top) {
        current = Math.floor(Math.random() * (top + 1));
        tmp = array[current];
        array[current] = array[top];
        array[top] = tmp;
    }

    return array;
}

// Randomly sort the array and take 6
randomArray = shuffle(arr).slice(0,6);

document.write("Random array: " + randomArray + "<br>");