public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc newbie: rand()
@ 1999-12-10  4:04 Joachim Bauernberger
  1999-12-10  4:40 ` Jan Dvorak
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Joachim Bauernberger @ 1999-12-10  4:04 UTC (permalink / raw)
  To: help-gcc

/*  hi there!
*
*  can anybody tell my why the following code compiled with:............

*  gcc -g -D_GNU_SOURCE filename.c -o outputfile
*
*  ....generates all sort of strange numbers but when compiled under
borland gives me the desired *   random numbers between 1 and 6  ??? how
do i do it to get the numbers between 1 and 6.
*  this example is from a book about C so it can't be that wrong, can
it?
*/

#include <stdlib.h>
#include <stdio.h>

#define SEED 12345

main()

{

    float x;
    int n;

        srand(SEED);

            x = rand() /32768.0;
            n = 1 + (int) (6 * x);

      printf("x = %d", n);
}

/*Thank's
                    Joachim!
*/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1999-12-31 22:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-10  4:04 gcc newbie: rand() Joachim Bauernberger
1999-12-10  4:40 ` Jan Dvorak
1999-12-31 22:24   ` Jan Dvorak
1999-12-10 22:18 ` Martin Kahlert
1999-12-31 22:24   ` Martin Kahlert
1999-12-12 14:41 ` Patrick Block
1999-12-31 22:24   ` Patrick Block
1999-12-12 15:29 ` Rick Dearman
1999-12-31 22:24   ` Rick Dearman
1999-12-12 15:35 ` Rick Dearman
1999-12-31 22:24   ` Rick Dearman
1999-12-31 22:24 ` Joachim Bauernberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).