nikhil,

Good point.
Caveat: But based on philips advice two pieces of code.
<sample>
#include <stdlib.h>
int main(){
int i;
srand(time(0));
for(i=0; i<10;i++)
  printf("%d, ", 1+(int) (10.0*rand()/(RAND_MAX+1.0)));
}</sample>
<output>
6, 2, 4, 6, 10, 2, 8, 3, 5, 2,
</output>

<bad sample>
#include <stdlib.h>
int main(){
int i;
for(i=0; i<10;i++,srand(time(0)))
  printf("%d, ", 1+(int) (10.0*rand()/(RAND_MAX+1.0)));
}
</bad sample>
<thus bad o/p>
6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
<thus bad o/p>
similar fundamental error in random no generation by
netscape's ssl long ago..

hth,
shailesh
--- Philip S Tellis <[EMAIL PROTECTED]> wrote:
> On Thu, 3 Oct 2002, Nikhil Joshi wrote:
> 
> > i guess it has something to do with seed (what is it
> anywayz ?) when i
> > call srand with different seed value it gives some
> other integer, but
> > again it *always* gives that integer only..
> 
> one generally calls srand with the current timestamp.
> 
> remember, one cannot generate random numbers by
> deterministic means.  a 
> classical computer is a deterministic engine and
> therefore *cannot* 
> generate random numbers.  They generate pseudo random
> numbers based on a 
> randomising function (see Knuth).  The function is
> dependent on the seed 
> being sufficiently random.  Picking the current
> millisecond value is a 
> good choice.
> 
> Philip
> 
> -- 
> They have been at a great feast of languages, and stolen
> the scraps.
>               -- William Shakespeare, "Love's Labour's Lost"
> 
> 
> _______________________________________________
> http://mm.ilug-bom.org.in/mailman/listinfo/linuxers
> 


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

_______________________________________________
http://mm.ilug-bom.org.in/mailman/listinfo/linuxers

Reply via email to