alert("0123456789".split("").sort(function(){return .5-Math.random()}).join(""));
This is probably one of the shortest ways to generate a 10-digit number in JavaScript that contains 10 digits from 0 to 9 in the randomized order. Example: 7205169483.
split("")//OK, it splits by chars because of empty separator
.sort(function(){return .5-Math.random()})
.join("")//joins with empty string as a separator
Why doesn't {return Math.random()}
work?
How many times .sort()
is executed - ten or one?