home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:11726 comp.sys.amiga.programmer:11792
- Newsgroups: comp.lang.c,comp.sys.amiga.programmer
- Path: sparky!uunet!darwin.sura.net!Sirius.dfn.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!seunet!swbull!hemulen.bull.se!elias
- From: elias@proxxi.se (Elias M}rtensson (proxxi))
- Subject: Re: Matt Dillon's DICE (Amiga C) and rand() function
- Message-ID: <1992Jul29.163704.26489@proxxi.se>
- Organization: proxxi
- References: <1992Jul29.081247.1@gallua>
- Date: Wed, 29 Jul 1992 16:37:04 GMT
- Lines: 60
-
- CADS_COLE@GALLUA.BITNET (Kevin Cole; Washington DC) writes:
-
- >Date Sent: 29-Jul-1992 08:09:36
-
- >Greetings from the void,
-
- >Here's a very short C program that doesn't do what the documentation claims.
- >According to Matt Dillon's DICE documents, I can limit the range of values
- >returned by rand() if I define the variable RAND_MAX to something other than
- >the default. I've tried various values, but I continue to get these huge
- >(32-bit) numbers. Tell me I'm not missing something obvious.
-
- >Thanx.
-
- > #include <stdio.h>
- > #include <stdlib.h>
- > #define RAND_MAX ((1023))
- > main()
- > {
- > int i;
- > for (;;)
- > {
- > i = rand();
- > printf("Random number %04X (%d)\n",i,i);
- > }
- > return(0);
- > }
- >--
-
- I have never used DICE but it looks like RAND_MAX is an extern int.
-
- Try this instead:
-
- #include < stdio.h>
- #include <stdlib.h>
-
- extern int RAND_MAX;
-
- main()
- {
- int i;
-
- RAND_MAX = 1023;
- for(;;){
- i = rand();
- printf( "Random number %04X (%d)\n", i, i );
- }
- return( 0 );
- }
-
- > ========== U.S. Mail =============================== E-Mail =================
- > Kevin Cole <Flatline> | Bitnet: CADS_COLE@GALLUA.BITNET
- > Gallaudet Research Institute (GRI) | Internet: KJCOLE@GALLUX.GALLAUDET.EDU
- > Washington, D.C. 20002-3625 | UUCP: ...!psuvax!gallua.bitnet!kjcole
- > (202) 651-5575 x4592 | The WELL: kjcole
-
- ###################
- # Elias Martenson #
- # elias@proxxi.se #
- ###################
-