Thread: Lotto 6/49 program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by flp1969
    I don't see why a random 32 bits value can generate more or less probable values due to modulo n
    Think about picking one of four restaurants to eat at for lunch using a single roll of a six-sided die: if you use the entire range of the die using modulo, then two of the restaurants will be twice as likely to be selected as the other two. For example, restaurant A will be selected if the die roll is 1 or 5, restaurant B will be selected if the die roll is 2 or 6, but restaurant C will only be selected if the die roll is 3, and restaurant D will only be selected if the die roll is 4. A simple solution to this is to discard the roll if it is 5 or 6, i.e., re-roll the die such that you only pick a random number within a range congruent to the number of options.

    That said, I'm not concerned with this slight bias at all when applied to wolly's problem: wolly needs to get going, not focus on this just yet, and fixing the range to eliminate the bias is not that difficult anyway.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by laserlight View Post
    Think about picking one of four restaurants to eat at for lunch using a single roll of a six-sided die: if you use the entire range of the die using modulo, then two of the restaurants will be twice as likely to be selected as the other two. For example, restaurant A will be selected if the die roll is 1 or 5, restaurant B will be selected if the die roll is 2 or 6, but restaurant C will only be selected if the die roll is 3, and restaurant D will only be selected if the die roll is 4. A simple solution to this is to discard the roll if it is 5 or 6, i.e., re-roll the die such that you only pick a random number within a range congruent to the number of options.
    Ahhhhh.... I keep forgeting about distribution. Thanks. Those values are very clear to me now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lotto program homework help
    By apelletier in forum C Programming
    Replies: 14
    Last Post: 03-11-2018, 02:09 PM
  2. Lotto program
    By MrQ in forum C Programming
    Replies: 3
    Last Post: 06-24-2013, 12:35 AM
  3. lotto program in c
    By vyshant in forum C Programming
    Replies: 7
    Last Post: 11-07-2011, 12:19 PM
  4. Lotto problem
    By Roaring_Tiger in forum C Programming
    Replies: 11
    Last Post: 03-13-2003, 10:17 PM
  5. Lotto game in C
    By fun2sas in forum C Programming
    Replies: 2
    Last Post: 03-02-2003, 07:19 PM

Tags for this Thread