Xref: utzoo comp.unix.xenix:8646 comp.lang.c:23925 Path: utzoo!attcan!uunet!samsung!usc!apple!sun-barr!lll-winken!decwrl!shelby!helens!relgyro!mike From: mike@relgyro.stanford.edu (Mike Macgirvin) Newsgroups: comp.unix.xenix,comp.lang.c Subject: Re: random number, how do I do it? Message-ID: <377@helens.Stanford.EDU> Date: 16 Nov 89 17:25:10 GMT References: <5726@ozdaltx.UUCP> Sender: news@helens.STANFORD.EDU Reply-To: mike@relgyro.STANFORD.EDU (Mike Macgirvin) Organization: Stanford Relativity Gyro Experiment (GP-B) Lines: 40 In article <5726@ozdaltx.UUCP> root@ozdaltx.UUCP (root) writes: >I am trying to write some code to generate a random number that would >fall between 0 and 65,000. I know there is something I'm missing >#include >main() >{ > extern unsigned short rand(); > extern unsigned long time(); > unsigned short offset; > while(1){ > srand((unsigned)getpid() + (unsigned)time(NULL)); > offset = rand(); > printf("NUMBER=%ld\n",offset); ^ > sleep(1); > } >} "%ld" means long int. 'offset' is a short int. You said so. I believe the behaviour you are seeking requires "%ud". Now I have to type in a bunch of junk for the line counter.. hit 'n' to avoid it. . . . . . . . . . . ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Mike Macgirvin Relativity Gyroscope Experiment (GP-B) + + mike@relgyro.stanford.edu (36.64.0.50) + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++