1 Reply Latest reply on Sep 5, 2007 2:42 AM by richiemotoki

    How to genrate non-repeating random numbers

    richiemotoki
      Hi everyone, i'm trying to write a for loop that genrate a list of non-repeating random index number for an array list but i can't seem to get the random numbers non-repeat. I'm a newbie in Flex 2 so it would be great if anyone could show me what seems to be the problem in this code:

      Thank you very much.
      Richie

      for (var j:Number = 0; j < tempArray.length; j++)
      {
      var randomNum:Number = Math.round(Math.random()*tempArray.length);


      if (j - 1 >= 0)
      {
      while (randomNum == randomIndex[j-1].index)
      randomNum = Math.round(Math.random()*tempArray.length);
      }

      //Push the random number in an array
      randomIndex.push({index: randomNum});
      Alert.show(randomNum.toString());
      }