A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Randomize an Aray?

  1. #1
    Junior Member
    Join Date
    Nov 2000
    Hello! Does nayone know a short script (Flash5) to make a new Array based on an existing one but with all items in random order? I've tried Array.Splice but I don't know much about programming.

    Thanks a lot in advance! Jean-francois

  2. #2
    Junior Member
    Join Date
    Jan 2001
    If you are having trouble with the .splice, you can use a For loop to run through a cycle of numbers and use Math.random() to generate a random number inside a value of 0 and x (x being a number you specify). Then with that, store these numbers in in 2 variables (stored_numberA, stored_numberB) and assign the variables you want to be random to the stored variables.

    I know its brief, but this will help. email helpmeben@yahoo.com and I will send you a example fla for you.


  3. #3
    Senior Member
    Join Date
    Jun 2001
    Virginia, USA
    myArray = new Array (1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
    tempArray = new Array();
    mylength = myArray.length - 1;
    for (count = mylength ; count>=0; count-- ){
       index = random(count);
       tempArray[count] = myArray[index];
       myArray[index] = myArray[count]
    myArray = tempArray;
    trace (myArray);

  4. #4
    Junior Member
    Join Date
    Nov 2000


    Thanks so much for the very fast reply!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center