How to jquery get 10 random numbers without repeating?

Hello, please tell me how to get 10 random integers without repetition in jquery or javascript in the range from 1 to 30 inclusive?
July 8th 19 at 15:59
3 answers
July 8th 19 at 16:01
Solution
var arr = [];
while (arr.length < 10) {
 var n = Math.floor(Math.random() * 30) + 1;
 if (arr.indexOf(n) == -1) {
arr.push(n);
}
}
always "10" returns( - nikita.Stracke commented on July 8th 19 at 16:04
: see the array arr, there will be values with arr.shift them out. - Violet_Wiso commented on July 8th 19 at 16:07
July 8th 19 at 16:03
// use Math.round() will give an uneven distribution!
function getRandomInt(min, max)
{
 return Math.floor(Math.random() * (max - min + 1)) + min;
}
Where is the guarantee that there will be repeats ? - nikita.Stracke commented on July 8th 19 at 16:06
: use an array where to put the resulting value and look for in this match. If there is, then generate a new number - Violet_Wiso commented on July 8th 19 at 16:09
I it with pleasure )) but the author of the question - not me. And you answered. So I wrote that the answer is incomplete, guarantee Nepovtorim no. - Tessie commented on July 8th 19 at 16:12
: Soren )) on the machine responded. And Yes, You are right. Well, I think the author read the comments and he will write the check. - Kameron_Hilpert34 commented on July 8th 19 at 16:15
July 8th 19 at 16:05
getRandomArbitary function(min, max)
{
 return Math.random() * (max - min) + min;
}


Taken from here

Find more questions by tags jQueryJavaScript