Wow! You didn't have to go to all that trouble, but thank you!
--- In [email protected], Charles Richmond <[EMAIL PROTECTED]> wrote: > > On Jan 21, 2008, at 10:52 PM, Charles Richmond wrote: > > > > > From: Vic Wagner <[EMAIL PROTECTED]> > > Date: January 17, 2008 11:38:18 PM CST > > To: [email protected] > > Subject: Re: [c-prog] Well, I did it! > > Reply-To: [email protected] > > > > > > onecrazeemom wrote: > >> I finally completed the dice roll program. Now, what do I do to make > >> the rolls more random? They seem to come up with doubles quite often. > >> I used srand( time(0)) to get my random numbers. I used the modulus(I > >> think that is what it is called) > >> > >> dieOne = 1 + rand() %6; > >> dieTwo = 1 + rand() %6; > >> > >> srand( time(0) ); > >> > >> Just curious what gives you a true random number when the lines of > >> code are run so close together. Here are a couple of rolls: > >> > >> 1. 3, 1 > >> 2. 6, 1 > >> 3. 6, 2 > >> 4. 5, 5 > >> 5. 1, 1 > >> 6. 3, 4 > >> 7. 4, 6 > >> > >> I guess they are more random than I thought, but the first two > >> times I > >> ran the program it came up with doubles. > >> > >> Thanks in advance, > >> Stephanie > > You should be using srand(time(0)); only ONCE in your program. > > and if you do the math, you'll find that about 1/6 of the rolls > > will be > > "doubles" > > > > > Here is the table of how two dice can combine: > > | 1 | 2 | 3 | 4 | 5 | 6 | > --+---+---+---+---+---+---+ > 1 | 2 | 3 | 4 | 5 | 6 | 7 | > --+---+---+---+---+---+---+ > 2 | 3 | 4 | 5 | 6 | 7 | 8 | > --+---+---+---+---+---+---+ > 3 | 4 | 5 | 6 | 7 | 8 | 9 | > --+---+---+---+---+---+---+ > 4 | 5 | 6 | 7 | 8 | 9 |10 | > --+---+---+---+---+---+---+ > 5 | 6 | 7 | 8 | 9 |10 |11 | > --+---+---+---+---+---+---+ > 6 | 7 | 8 | 9 |10 |11 |12 | > --+---+---+---+---+---+---+ > > > The main diagonal from upper left to lower right... represents the > six doubles that can be rolled. Six out of thirty-six is one out of six. > So one out of six times (on average) you *should* roll a double. > > -- > +----------------------------------------------------------------+ > | Charles and Francis Richmond richmond at plano dot net | > +----------------------------------------------------------------+ >
