random number, how do I do it?

root root at ozdaltx.UUCP
Thu Nov 16 11:58:10 AEST 1989


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
here, but can't seem to pin it down.  I feel like the problem is in
the type declarations, but have tried most combinations with not a lot
of success.  Any suggestions?

Sample code:
------------------------------
#include <stdio.h>
main()
{
    extern unsigned short rand();
    extern unsigned long time();
    unsigned short offset;

/* generate a random number using time and pid as seed */

   while(1){
    srand((unsigned)getpid() + (unsigned)time(NULL));
    offset = rand();
    printf("NUMBER=%ld\n",offset);
    sleep(1);
  }

}
------------------
Thanks
Scotty
AIDS INFORMATION EXCHANGE BBS      (214) 247-2367/247-5609
               "Education is the best weapon"
     {ames,rutgers,texsun,smu}!attctc!ozdaltx!sysop 



More information about the Comp.lang.c mailing list