Click to See Complete Forum and Search --> : non-repeating random array


simonbau
02-19-2003, 07:06 AM
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>

gil davis
02-19-2003, 08:12 AM
Originally posted by simonbau
window.location=foto[randomNumber(foto.length -1)];This will negate any attempt to remember which foto was used since the browser's memory gets erased when you change the location.