# Avoiding the repetion of random numbers. HOW DO I PLACE MY CODE IN LOOP OF A FUNCTION

stiil struggling:
words=["Which is the capitol of Italy?","Which is the capitol of Spain?","Which is the capitol of France?","Which is the capitol of Holland?"];
randvalue=Math.round(Math.random()*4);
word=words[randvalue];
trace(word);

This was my help to the first question:

randValue = Math.round(Math.random()*words.length);
word = words.splice[randvalue, 1];  //removes that value from the array ensuring it's not repeated, and assigns it to word
trace word;

HOW DO I  place thhis in a function of a loop, that should do it. (THIS IS MY QUESTION!!!!!)
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Sorry about the wording, should have been "place in a function OR a loop", so for a loop:

words=["Which is the capitol of Italy?","Which is the capitol of Spain?","Which is the capitol of France?","Which is the capitol of Holland?"];
for(var i = 0; i < words.length; i++){
randValue = Math.round(Math.random()*words.length);
word = words.splice[randvalue, 1];  //removes that value from the array ensuring it's not repeated, and assigns it to word
//do what you need to do here, assign to an array to store them randomly, or som other action
}

that will loop through, now keep in mind that that will loop through each of the items in a random order, but won't stop (as it's written) to do anything else.

or for a function to be called, place this on the first frame:
function getWord():String{
randValue = Math.round(Math.random()*words.length);
word = words.splice[randvalue, 1];  //removes that value from the array ensuring it's not repeated, and assigns it to word
return word;
}

then if you call that function:
myNewWord = getWord();
It will get you a new word from your list.  This particular setup has no checking for whether you're at the end of the list though.  Feel free to respond here if any of that doesn't make sense.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.