Nová ukázka
Reset
Načíst z URL
Uložit a získat odkaz
Vztahuje se k…
Nevyplňujte
Napiště „nejsem robot“
▶
Přepnout zobrazení
Výsledek
HTML
Autoformát
Standardní režim
Mobilní zobrazení
CSS
Autoformát
CSS reset
Až na konci
function randomSet(n, min, max) { // there are not enough numbers in the interval if (max - min + 1 < n) { return null; } // we start with an empty array var numbers = []; // we will generate n numbers for (var i = 0; i < n; i++) { do { // this generates a number in range [min, max] with borders included var rnd = Math.floor(Math.random() * (max - min + 1)) + min; } while (numbers.indexOf(rnd) != -1); // while rnd is in the array numbers // the loop ended and therefore rnd has not been chosen yet numbers.push(rnd); } return numbers; } var myNumbers = randomSet(3, 0, 100); document.write(myNumbers);
J
ava
S
cript
Autoformát
jQuery
Umístění JS
window.onload
</head>
</body>