17 Replies Latest reply on Oct 4, 2006 4:40 AM by bonsubhan

    randomization of an array

    bonsubhan
      i want to randomize the array values and to avoid displaying duplicate values.

      here I am havig a movie clip in which it has the variable called "keyLabel"(text field). like this iam havig ten movi clip which had instance name "zero","one", "two", "three", "four", "five", "six", "seven", "eight" and "nine".
      in this movi clip i want to display the ten numbers 0 to 9 in the variable "keyLable" randomly each time when I open the swf file.

      here is the script what i had written. it randomize the array values, but i could not able to avoid duplicate values.

      can somebody help me in this issue.

      thanks


      var tempArray:Array=new Array("0","1", "2", "3", "4", "5", "6", "7", "8", "9");

      numbers = new Array();
      numberText = new Array("zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine");




      for(ip=0; ip<10; ip++)
      {

      numbers[ip]=random(tempArray[ip]);

      _root[numberText[ip]].keyLabel = numbers[ip];

      }
      trace (numbers);