Losowa liczba w javascript

Losowa liczba z zakresu od min do max (inclusive)

function getRandomNumber(min, max){
    return Math.random() * (max - min + 1) + min;
}

Funkcja generująca losowy kolor w postaci szesnastkowej

function getRandomColor(){
    return randomColor = '#'+ Math.floor(Math.random()*16777215).toString(16).padStart(6, '0')
}

Funkcja generująca losowy kolor rgb

function getRandomNumber(min, max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

function getRandomRGB(){
    let r = getRandomNumber(0, 255);
    let g = getRandomNumber(0, 255);
    let b = getRandomNumber(0, 255);
    return 'rgb(' + r + ', ' + g + ', ' + b + ')';
}
Ask ChatGPT
Set ChatGPT API key
Find your Secret API key in your ChatGPT User settings and paste it here to connect ChatGPT with your Tutor LMS website.
Scroll to Top