JavaScriptã§é åãã·ã£ããã«ãã話ãè¦ã¦ãããããã°Array#shuffleã¯ä»¥åæ¸ããè¨æ¶ããããªã¼ã¨æã£ã¦èª¿ã¹ã¦ã¿ããã³ããã ã£ãã http://www.fumiononaka.com/TechNotes/Flash/FN0212002.html Fisher-Yatesã¨ããã¢ã«ã´ãªãºã ã ããã§ãã Array.prototype.shuffle = function() { var i = this.length; while(i){ var j = Math.floor(Math.random()*i); var t = this[--i]; this[i] = this[j]; this[j] = t; } return this; } a = [1,2,3,4,5]; a.shuffle() // 3,1,5,2,4 a // 3,1,5,2,4 ããæ®éã«å®è£
{{#tags}}- {{label}}
{{/tags}}