Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Created December 9, 2010 21:59
Show Gist options
  • Select an option

  • Save nathansmith/735401 to your computer and use it in GitHub Desktop.

Select an option

Save nathansmith/735401 to your computer and use it in GitHub Desktop.
Randomize a JavaScript array
function randomize() {
return Math.round(Math.random()) - 0.5;
}
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120].sort(randomize);
@mathiasbynens
Copy link

Microsoft got a lot of shit for using this: http://www.robweir.com/blog/2010/02/microsoft-random-browser-ballot.html Something to keep in mind.

@nathansmith
Copy link
Author

Ah, I was just using it to dummy up some charts in an HTML prototype.

But yeah, wouldn't want to skew real data. Awesome article, by the way!

@mathiasbynens
Copy link

Yeah, sure seems random enough for most things :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment