JSFiddle - React, Tailwind, and code Playground

by Bacco

JavaScript

var max = 20;

var i, j, t, set = [];
for( var i = 1; i < max; i++ ) set.push( i );

for( i = 1; i < ( max - 1 ); i++ ) {
    j = i + ( Math.round( Math.random() * ( max - i - 1 ) ) );
    t = set[j];
    set[j] = set[i - 1];
    set[i - 1] = t;
}

// Exibir resultado:
for( i = 0; i < 6; i++ ) console.log( set[i] );