Mail Archives: djgpp/1998/03/29/18:00:40
John M. Aldrich wrote:
>
> Paul Derbyshire wrote:
> >
> > How quickly does srandom() in DJGPP's libc execute? Would an added
> > srandom() before every random() in a program that uses random()
> > extensively cause a noticeable slowdown? Reason I ask is because
> > something like that might be necessary to make a threadsafe random
> > number generator class so that each random number generator instance
> > can be seeded independently and give consistent results.
>
> I think I understand what you're saying. However, calling srandom()
> before each call to random() is a nearly foolproof way to _not_
> generate a random sequence of numbers.
i think what he has in mind is more like
/* untested code */
#include <stdlib.h>
class CMyRandom
{
private :
int last_value;
public :
CMyRandom()
{
last_value = random();
}
CMyRandom(int seed)
{
last_value = seed;
}
int value(void)
{
srandom(last_value);
last_value = random();
return last_value;
}
};
i don't think the overhead of srandom() would be substantial.
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -