hi folks,
            just wanted to share something with you guys and get your views
on the problem at hand.

            even though this is not inherently a C or C++ language problem,
i am sure it will interest you ppl.

            what i have is a random5generator() which gives me values
0,1,2,3 and 4 with equal probability.

            now the problem is to build a random7generator()(which would
give me 0,1,2,3,4,5 and 6 with equal probability) using the
random5generator() at hand.

            the easiest way to do it is of course using the
random5generator() function more than once and add the values and then use
the remainder or modulus function to get the values.

            these are the results i got.

            when i implemented the random7generator() as random7generator()
= (random5generator() + random5generator())%7
            and determined the various possible outcomes, the results were
like this 0 could come in 3 ways(0+0=0, 3+4=7%7=0, 4+3=7%7=0)

           similarly 1 could result in 3 ways,
                        2 in 3 ways,
                        3 in 4 ways,
                        4 in 5 ways,
                        5 in 4 ways
                  and 6 in 3 ways.

           this way deviation between the min and max values came as 2(max
value was 5(for 4) and min value was 3(for 2 and 6))
           next i determined the deviation percentage as deviation/max value
*100% = 2/5 = 0.4

          next i changed the random7generator() as random7generator() =
(random5generator() + random5generator() + random5generator())%7
          now 0 could result in 19 ways,
                 1 could result in 18 ways,
                 2 could result in 16 ways,
                 3 could result in 16 ways,
                 4 could result in 18 ways,
                 5 could result in 19 ways,
          and  6 could result in 19 ways.

                 now deviation percentage came as 3/19*100 = 0.1578

           next used random5generator() 4 times.
                  now dev perc came as 0.0645

           next used random5generator() 5 times.                   now dev
perc came as 0.0226

           next used random5generator() 6 times.                   now dev
perc came as 0.0084

           next used random5generator() 7 times.                   now dev
perc came as 0.0029

           next used random5generator() 8 times.                   now dev
perc came as 0.0010

           next used random5generator() 9 times.                   now dev
perc came as 0.0003

           next used random5generator() 10 times.                   now dev
perc came as 0.0001

            now the results tell us that the more times we use the
random5generator() function to get the random7generator(), the more
equiprobable the values 0,1,2,3,4,5 and       6 become as the deviation
percentage( dev perc) decreases.

             so wouldn't use of random5generator() 100 times give us a real
close approximate of the random7generator() function.

             what do u ppl think?
             anything else anyone would like to propose to use as the
random7generator() which gives perfect results or is the perfect
random7generator() just hypothetical.
             waiting to hear all ur views.

            thanks again for your patience,

            must say i am a huge fan of this group for its ability to come
up with innovative cerebrations.

            hulk.


[Non-text portions of this message have been removed]

Reply via email to