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:
After declaring your array:

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!!!!!)
andreafpAsked:
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.

SavongCommented:
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

Your issues matter to us.

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

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.