Nikhil Joshi wrote: > Hi! i've taken this code straight from man rand it is > supposed to generate random number between 1 and 10 > > j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); > > now when I print j it *always* gives 9
Subsequent calls (in the same instance of the program) will not *always* yield 9. You're re-running the program with the same seed. > when i call srand with different seed value it gives some > other integer, but again it *always* gives that integer Again, subsequent calls with not give the same integer *always*. If you're only calling rand() once in your program and want it to give a diffirent integer each time then you can seed it with the current time -- srand((unsigned int) time(NULL)); j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); Manish _______________________________________________ http://mm.ilug-bom.org.in/mailman/listinfo/linuxers

