random number, how do I do it?
Mike Macgirvin
mike at relgyro.stanford.edu
Fri Nov 17 04:25:10 AEST 1989
In article <5726 at ozdaltx.UUCP> root at 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 <stdio.h>
>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 at relgyro.stanford.edu (36.64.0.50) +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
More information about the Comp.lang.c
mailing list