Created
December 9, 2010 21:59
-
-
Save nathansmith/735401 to your computer and use it in GitHub Desktop.
Randomize a JavaScript array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function randomize() { | |
| return Math.round(Math.random()) - 0.5; | |
| } | |
| [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120].sort(randomize); |
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!
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
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.