JSFiddle - React, Tailwind, and code Playground

by FishBasketGordo

JavaScript

var randomArr = [],
    trackingArr = [],
    targetCount = 4,
    currentCount = 0,
    min = 1,
    max = 10,
    rnd;

while (currentCount < targetCount) {
    rnd = Math.floor(Math.random() * (max - min + 1)) + min;
    if (!trackingArr[rnd]) {
        trackingArr[rnd] = rnd;
        randomArr[currentCount] = rnd;
        currentCount += 1;
    }
}

alert(randomArr); // Will contain four unique, random numbers between 1 and 10.