In PHP gibt es ein praktisches Feature namens shuffle() , die ein Array mischen (siehe ermöglicht sehr kurze Trick: Nehmen zufällige Elemente aus einem Array in PHP ). Eine große Version für Javascript fand ich es hier . Unten ist der Code leicht überarbeitet:
1 2 3 | = function ( ) { Array. Prototype. Shuffle = function () { var j , x , i = this . length ; i ; j = Math. floor ( Math. random ( ) * i ) , x = this [ -- i ] , this [ i ] = this [ j ] , this [ j ] = x ) ; for (var j, x, i = diese Länge; i; j = Math Etage (Math. random () * i), x = this [- i], diese [i] = this [j], diese.. [j] = x); } |
al posto di parseInt() , in quanto da test effettuati è risultato estremamente più veloce, almeno sulla mia macchina e con FireFox 3. Im Vergleich zum ursprünglichen I erweitert das Objekt Array und eingefügt Math.floor() statt parseInt() , als Folge der durchgeführten Tests ist extrem schneller, zumindest auf meinem Rechner und FireFox 3.
In ActionScript 3.0, habe ich es in die Klassenzimmer MatrixArray :
1 2 3 4 5 6 7 8 | / ** * Shuffle in Zufallsmatrix * * / shuffle ( ) : void { public function shuffle (): void { / / Dank http://jsfromhell.com/array/shuffle var j , x , i = __len ; i ; j = Math . floor ( Math . random ( ) * __len ) , x = this [ -- i ] , this [ i ] = this [ j ] , this [ j ] = x ) ; for (var j, x, i = __ len, i; j = Math . Etage ( Math . random () * __ len), x = this [- i], diese [i] = this [j], diese [j ] = x); } |










[...] Bereits darüber, wie Sie die Methode shuffle () in Javascript und Actionscript Umsetzung gesprochen. Ich erkannte, tuttaavia, nicht darauf hingewiesen haben, dass auch in der Lage, Actionscript [...] ist
Dies ist meine eigene Lösung: http://www.daveoncode.com/2009/01/08/implementing-arrayshuffle-in-actionscript/
Es ist nur 3 Zeilen Code und es funktioniert gut
@ DaveOnCode: sehr kurze Schnipsel
thx
[...] Wie in sehr kurze Schnipsel gesehen: shuffle () in Javascript und Actionscript. [...]