• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Tracing a spliced array more than once

Community Beginner ,
Jul 12, 2012 Jul 12, 2012

Copy link to clipboard

Copied

I am trying to create a randomizing  function that returns the contents of an array once in a random order. I have the following array:

var randomArray:Array=["one","two","three"]

and I have the following code inside the function:

var r:int=Math.floor(Math.random()*randomArray.length);

trace(randomArray.splice(r,1));

It traces the array once through randomly, but stops when it gets to the end of the array. I suppose that is due to the splice command. What do I need to do to have the function constantly call a new random ordering, instead of stopping once it runs through the first trace?

TOPICS
ActionScript

Views

344

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2012 Jul 12, 2012

Copy link to clipboard

Copied

LATEST

I don't see how that does what you say you want it to do (returns the contents of an array in random order)... it is not randomizing the order of the array.  It is removing things from it.

What do you have that continually calls the functions or that calls for retracing within the function?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines