[gameprogrammer] Re: Random Integer Problem :(
- From: "Engin Çalar" <engincalar@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Sun, 24 Sep 2006 11:33:25 +0300
in my first game-try (sth like minesweeper of windows) i used
glutGet(GLUT_ELAPSED_TIME);
and used the returning value for the random func and i seem to remember i
used the random func 2 times for 1 mine..
the result :: it really worked and seems like real random:P numbers...not
1-4-3-1-4-3 or sth like that
2006/9/24, Andrew Falgout <andrew.falgout@xxxxxxxxx>:
Perhaps you can explain why the modulus would be the improper way of
getting a random number?
On 9/24/06, Olivier Delannoy < olivier.delannoy@xxxxxxxxx> wrote:
>
> In Numerical Recipes in C: The Art of Scientific Computing
> (William H.
> Press, Brian P. Flannery, Saul A. Teukolsky, William T.
> Vetterling; New
> York: Cambridge University Press, 1992 (2nd ed., p. 277)), the
> follow-
> ing comments are made:
>
> "If you want to generate a random integer between 1 and
> 10, you
> should always do it by using high-order bits, as in
>
> j = 1 + (int) (10.0 * (rand() / (RAND_MAX + 1.0)));
>
> and never by anything resembling
>
> j = 1 + (rand() % 10);
>
>
> from unix man page of rand
> $> man 3 rand
>
> On 9/24/06, Chris Nystrom <cnystrom@xxxxxxxxx> wrote:
> >
> >
> > On 9/23/06, Sahan Chandrasekara < sahanthegamecreator@xxxxxxxxx>
> wrote:
> > > Hi,
> > >
> > > I'm trying to use this code to generate a random number between 1
> and six
> > inclusive:
> > >
> > >
> > > int random_int() {
> > > srand(time(NULL));
> > > int random_num=rand()%7;
> > > return random_num;
> > > }
> > >
> > > But it dosen't work. My program is programmed to quit immediantly if
> the
> > number is not between 1 and six inclusive, and that is what it does
> >
> > I believe for 1-6 you want something like:
> >
> > random_num = ((rand() % 6) + 1);
> >
> > Chris
> >
> > --
> > E-Mail: Chris Nystrom <cnystrom@xxxxxxxxx >
> > http://www.newio.org/
> > AIM: nystromchris
>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
--
./Andrew
--
Just say the words , your wish is my command..
- References:
- [gameprogrammer] Random Integer Problem :(
- From: Sahan Chandrasekara
- [gameprogrammer] Re: Random Integer Problem :(
- From: Chris Nystrom
- [gameprogrammer] Re: Random Integer Problem :(
- From: Olivier Delannoy
- [gameprogrammer] Re: Random Integer Problem :(
- From: Andrew Falgout
Other related posts:
- » [gameprogrammer] Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
- » [gameprogrammer] Re: Random Integer Problem :(
Perhaps you can explain why the modulus would be the improper way of getting a random number?
On 9/24/06, Olivier Delannoy < olivier.delannoy@xxxxxxxxx> wrote:
>
> In Numerical Recipes in C: The Art of Scientific Computing
> (William H.
> Press, Brian P. Flannery, Saul A. Teukolsky, William T.
> Vetterling; New
> York: Cambridge University Press, 1992 (2nd ed., p. 277)), the
> follow-
> ing comments are made:
>
> "If you want to generate a random integer between 1 and
> 10, you
> should always do it by using high-order bits, as in
>
> j = 1 + (int) (10.0 * (rand() / (RAND_MAX + 1.0)));
>
> and never by anything resembling
>
> j = 1 + (rand() % 10);
>
>
> from unix man page of rand
> $> man 3 rand
>
> On 9/24/06, Chris Nystrom <cnystrom@xxxxxxxxx> wrote:
> >
> >
> > On 9/23/06, Sahan Chandrasekara < sahanthegamecreator@xxxxxxxxx>
> wrote:
> > > Hi,
> > >
> > > I'm trying to use this code to generate a random number between 1
> and six
> > inclusive:
> > >
> > >
> > > int random_int() {
> > > srand(time(NULL));
> > > int random_num=rand()%7;
> > > return random_num;
> > > }
> > >
> > > But it dosen't work. My program is programmed to quit immediantly if
> the
> > number is not between 1 and six inclusive, and that is what it does
> >
> > I believe for 1-6 you want something like:
> >
> > random_num = ((rand() % 6) + 1);
> >
> > Chris
> >
> > --
> > E-Mail: Chris Nystrom <cnystrom@xxxxxxxxx >
> > http://www.newio.org/
> > AIM: nystromchris
>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
-- ./Andrew
- [gameprogrammer] Random Integer Problem :(
- From: Sahan Chandrasekara
- [gameprogrammer] Re: Random Integer Problem :(
- From: Chris Nystrom
- [gameprogrammer] Re: Random Integer Problem :(
- From: Olivier Delannoy
- [gameprogrammer] Re: Random Integer Problem :(
- From: Andrew Falgout