4 Replies Latest reply on Jul 13, 2006 4:06 PM by Applied CD

    Random weighting

    ManOfMac Level 1
      It's easy to think of but hard to code.... imagine this..

      there are 3 sections: 2 with 10 items & 1 with 5
      Loop thru them all
      No problems

      BUT WHAT IF YOU WANT

      section 1 items favoured 70% of the time (show 70 times out of 100)
      Section 2 items favoured 20% of the time (show 20 times out of 100)
      Section 3 items favoured 10% of the time (show 10 times out of 100)

      Random works if they all have even bias but this doesnt work in the apporach above.

      I have 3 seperate lists for each of the sections so I can manage the random choosing of individual items easily enough, just need to develop a routine to let Director pick which of the 3 sections it should choose next.

      I could hardcode it to show "section 1" 70/100, "section 2" 20/100 etc. but only if it plays all of section 1 then all of section2 and so on !! It needs to be mixed up enough that it avoids displaying sections in large chunks...

      I expect this could be routine for a mathematician but alas I am not he !!!

      Any light greatly appreciated !!
        • 1. Re: Random weighting
          Level 7
          I'm not sure what exactly you are trying to do, but you can use random
          to figure out which list to use.

          case random(10) of
          1,2,3,4,5,6,7:
          --do something 70% of the time
          8,9:
          --do something 20% of the time
          10:
          --do something 10% of the time
          end case
          • 2. Re: Random weighting
            ManOfMac Level 1
            YEah I sortta looked a that but random is totally random.

            --Cancel, that your genius is in the simplicity.

            Just did a rough test and it produces results within a reasonable tolerance. ( 65-80 out of 100, 25-35 out of 100, 5-12 out of 100)

            FYI: I have 3 sections (Top 10, Coming Soon & Specials) I want the user to set the importance of the 3 sections and the larger the importance the more regulary it's displayed !!
            • 3. Re: Random weighting
              Level 7
              > Just did a rough test and it produces results within a reasonable
              > tolerance. (
              > 65-80 out of 100, 25-35 out of 100, 5-12 out of 100)

              Try something like this:

              on testRandom(loops)
              a=0
              b=0
              c=0
              m=float(loops)
              repeat with i = 1 to m
              case random(10) of
              1,2,3,4,5,6,7:
              a=a+1
              8,9:
              b=b+1
              10:
              c=c+1
              end case
              end repeat
              put a/m*100&"%,"&&b/m*100&"%,"&&c/m*100&"%"
              end

              --message window
              testRandom(1000000)
              -- "70.0128%, 19.9946%, 9.9925%"


              • 4. Re: Random weighting
                Applied CD Level 1
                Hey, I just throwing this out there for fun, but one of the few things I remember from grad school is that the probability of a particular set of multiple events is the product of the probability of each event separately. So for example, if you have 3 groups 1, 2, 3, and the items in each group are as follows:

                1 = A, B, C, D, E, F, G, H, I, J
                2 = A, B, C, D, E, F, G, H, I, J
                3 = A, B, C, D, E

                You’ve told us that the probability for group selection is 1=0.7, 2=0.2, and 3=0.1, the probability for item selection in each group is 1/(number of items in group) or 0.1 for groups 1 and 2, 0.2 for group 3. So…
                the probability of getting a particular item in group 1 is 0.7 * 0.1 = 0.07 or 7% (for each of 10 items)
                the probability of getting a particular item in group 2 is 0.2 *0.1 = 0.02 or 2% (for each of 10 items)
                the probability of getting a particular item in group 3 is 0.1*0.2=0.02 or 2% (for each of 5 items)

                So, given your numbers, you’ve got the unintuitive situation of a specific item in group 3 appearing with the same frequency as a specific item in group 2, although group 2 items will appear twice as frequently as a whole than group 3 items.