hallo
i would like to pick random elements from an array. every element can be chosen only once. when all elements are chosen the script stops. how do i have to change the following script so that every element can only be chosen once?
thanks simon baumgartner (switzerland)
<script language="javascript" type="text/javascript">
// Fotoliste
var foto = new Array();
foto[0]="foto1.html"
foto[1]="foto2.html"
foto[2]="foto3.html"
foto[3]="foto4.html"
foto[4]="foto5.html"
// Zufallszahl
function randomNumber(n){
number= Math.floor(Math.random() * (n+1));
return number;
}
window.location=foto[randomNumber(foto.length -1)];
</script>
i would like to pick random elements from an array. every element can be chosen only once. when all elements are chosen the script stops. how do i have to change the following script so that every element can only be chosen once?
thanks simon baumgartner (switzerland)
<script language="javascript" type="text/javascript">
// Fotoliste
var foto = new Array();
foto[0]="foto1.html"
foto[1]="foto2.html"
foto[2]="foto3.html"
foto[3]="foto4.html"
foto[4]="foto5.html"
// Zufallszahl
function randomNumber(n){
number= Math.floor(Math.random() * (n+1));
return number;
}
window.location=foto[randomNumber(foto.length -1)];
</script>