+ 5

Random Number Series in JS

I want to generate 0,to 11 numbers randomly.. for example: "0,4,2,1,7,9,11,3,6,8,5,10" not like this "0,1,6,6,5,3,2,2,11,8,9,13" How can i do it

25th Apr 2018, 10:19 AM
DarkZeus
DarkZeus - avatar
7 Respostas
+ 8
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] function shuffle(o) { for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o; }; var random = shuffle(numbers); document.write(random); // by mirage //for M.A.sunera Madanperuma
25th Apr 2018, 11:07 AM
Ahlin Chan
Ahlin Chan - avatar
+ 8
Math.floor(Math.random()*11);
25th Apr 2018, 10:29 AM
Ahlin Chan
Ahlin Chan - avatar
+ 7
if you want from 1 to 11 Math.floor(Math.random()*11 + 1)
25th Apr 2018, 10:30 AM
Ahlin Chan
Ahlin Chan - avatar
25th Apr 2018, 11:07 AM
Ahlin Chan
Ahlin Chan - avatar
+ 6
welcome also thank you for making my answer as best answer
25th Apr 2018, 2:12 PM
Ahlin Chan
Ahlin Chan - avatar
+ 5
Thank you very much broo
25th Apr 2018, 2:11 PM
DarkZeus
DarkZeus - avatar
+ 4
nope it repeats numbers i want to randomize numbers between 0 and 11 not to get 0 to 11 numbers randomly
25th Apr 2018, 10:34 AM
DarkZeus
DarkZeus - avatar