»
AnglaisFran�aisVietnamien

Imprimer - Array Randomiser - JavaScriptBank.com

Version compl�te: jsB@nk » Calcul » Array Randomiser
URL: https://www.javascriptbank.com/array-randomiser.html

Array Randomiser © JavaScriptBank.comCeci est un exemple d'utilisation de la Array () de l'objet propre de la méthode de tri aléatoire elle-même. Très simple et propre.

Version compl�te: jsB@nk » Calcul » Array Randomiser
URL: https://www.javascriptbank.com/array-randomiser.html



HTML
<script language="JavaScript"><!--//  by Roland Levy [email protected] randomisedArray(max){counter = max ;finalArray = new Array() ;prevArray  = new Array() ;for (i = 0; i < max; i ++) prevArray[i] = i + 1 ;for (j = 0; j < max; j ++){tempArray = new Array() ;rand = Math.round(Math.random() * (counter-1)) ; finalArray[j] = prevArray[rand]x = 0for (k = 0; k < counter; k ++){ if (k != rand){tempArray[x] = prevArray[k] ;x ++ ;}}counter -- ;prevArray = tempArray ;}return finalArray}result = 0while (!result){result = prompt("Random array Length : ", 10)result = ((result == "") + parseFloat(result)) ? result : false}msg = "Ordered array: "for (i = 1; i <= result; i ++) msg += i + ((i < result) ? "," : "<BR>")msg += "Random array: " + randomisedArray(result)document.write(msg) ;//--></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->