JSFiddle - React, Tailwind, and code Playground

JavaScript

function unique_randoms(length, maximum) {
  var numbers = [];
  var test;

  for (var i = 0; i < length; i++) {
    do {
      test = Math.floor(Math.random() * maximum);
    } while (numbers.indexOf(test) != -1);

    numbers.push(test);
  }

  return numbers;
}

console.log(unique_randoms(5, 10));