Walter, when you roll two dice, you get two random numbers between 1 and 6 inclusive. Each has an essentially uniform distribution, but the sum does not. Of every 36 rolls, you will average one 2, two 3s, three 4s, four 5s, five 6s, six 7s, five 8s, four 9s, three 10s, two 11s, and one 12. The same kind of thing would happen if you rolled two 5- sided dice or generated two 1-5 random numbers. Right?
So multiplying one of them by 5 really does make a difference, and the difference is that if the 1-5 random numbers are uniform, so is 5*one + the other. Dave On Sep 20, 5:52 pm, Walter <[email protected]> wrote: > Isn't it the same of adding two random numbers???? > > When you just add two random numbers, you tend to normalize them. If > you simply multiply one > of them by 5 before adding with the other, you'll end up normalizing > them the same way... > > On 18 set, 18:45, eSKay <[email protected]> wrote: > > > > > okay now I get it. > > > but then > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > int i; > > do > > { > > i = 5 * (rand5() - 1) + rand5(); // i is now uniformly random > > between 1 and 25 > > > } while(i > 7); > > > return i; > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > should be fine. isn't it?? > > > On Sep 18, 6:06 pm, Dave <[email protected]> wrote: > > > > What is wrong with using i = rand5() + rand5() instead of i = 5 * rand5 > > > () + rand5() is that the former is not uniformly distributed between 1 > > > and 10, as claimed. First, 1 never occurs. 2 occurs 1 out of 25 times, > > > 3 occurs 2 out of 25, etc. (Think of rolling two ordinary dice.) > > > > Dave > > > > On Sep 18, 6:19 am, eSKay <[email protected]> wrote: > > > > > one of the solutions given > > > > athttp://stackoverflow.com/questions/137783/given-a-function-which-prod... > > > > is: > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > int i; > > > > do > > > > { > > > > i = 5 * (rand5() - 1) + rand5(); // i is now uniformly random > > > > between 1 and 25} while(i > 21); > > > > > // i is now uniformly random between 1 and 21 > > > > return i % 7 + 1; // result is now uniformly random between 1 and 7 > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > > Why do we need to go for all this trouble?? > > > > > Why not: > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > int i; > > > > do > > > > { > > > > i = rand5() + rand5(); // i is now uniformly random between 1 and > > > > 10} while(i > 7); > > > > > // i is now uniformly random between 1 and 7 > > > > return i; > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > Whats wrong with it?? > > > > > On Sep 9, 12:34 am, Ramaswamy R <[email protected]> wrote: > > > > > > Generate the random number 7 times. Sum them all and divide by 5. > > > > > Theoritically it should be evenly distributed over 1-7. But owing to > > > > > random > > > > > number generators characteristics the sum of rand(5) called 7 times > > > > > may not > > > > > be perfectly evenly distributed over 1-7. > > > > > A nice discussion on some neat options is available here > > > > > -http://stackoverflow.com/questions/137783/given-a-function-which-prod... > > > > > > Rejection technique is pretty standard for this and yet simple. > > > > > > On Mon, Sep 7, 2009 at 8:56 AM, ankur aggarwal > > > > > <[email protected]>wrote: > > > > > > > Given a random number generator that generates numbers in the > > > > > > range 1 to > > > > > > 5, how can u create a random number generator to generate numbers > > > > > > in the > > > > > > range 1 to 7. (remember that the generated random numbers should > > > > > > follow a > > > > > > uniform distribution in the corresponding range) > > > > > > -- > > > > > Yesterday is History. > > > > > Tomorrow is a Mystery. > > > > > Today is a Gift! That is why it is called the Present :). > > > > > >http://sites.google.com/site/ramaswamyr-Hidequotedtext - > > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---
