1 Reply Latest reply on Nov 13, 2008 2:18 AM by Newsgroup_User

    Generate random numbers in pairs?

    dd4455 Level 1
      I have some code that generates a series of random numbers between 1 and 10:
      i = 1;
      while (Number(i)<>11) {
      rnd = random(10);
      x = 1;
      while (Number(x)<>Number((Number(length(Temp))+1))) {
      if ((substring(Temp, x, 1)) eq rnd) {
      rnd = "";
      }
      x = Number(x)+1;
      }
      if (rnd ne "") {
      Temp = Temp add rnd;
      i = Number(i)+1;
      }
      }
      nextFrame();

      So this I might get is: 6154078293
      How can I modify this so that it produces a list of random numbers, in pairs, like:
      6-1
      5-4
      0-7
      8-2
      9-3
        • 1. Re: Generate random numbers in pairs?
          Level 7
          // as2
          // will give you an array of 5 times of random pairs
          // from the content of the array numbers

          var numbers= [0,1,2,3,4,5,6,7,8,9];
          Array
          rand = []
          for(n=0;n<10;){
          pair = []
          for (p=0;p<2;p++){
          idx = random( numbers.length -1)
          trace (idx + " " + numbers.length)
          pair[p] = numbers[idx];
          numbers.splice(idx,1)
          n++
          }
          rand[rand.length] = pair;
          }
          // will not displayed as pairs but you can see it in the debugger
          trace (rand)