Mail Archives: djgpp/1998/03/07/03:14:41
Ahn Ki-yung escribió:
> I wonder what does these libc functions do ?
> In the libc reference info file there are 3 random functions.
> They are rand, random, srandom.
> The function "rand(unsigned int)" is not found but there is a prototype
> in "stdlib.h"
>
> Anyway the info file says about the function srandom like this
>
> > srandom
> > =======
> > Syntax
> > ------
> > #include <stdlib.h>
> > int srandom(int seed);
> >
> > Description
> > -----------
> > This function initialized the random number generator (random.).
> > Passing the same SEED results in `random' returning predictable
> > sequences of numbers.
> >
> > Return Value
> > ------------
> > Zero.
> >
> > Example
> > -------
> > srandom(45);
>
> What does this mean. I can't get any idea from the example.
> So I tried to find out the difference before calling the function
> "srandom"
> I tried several times but I couldn't find any difference!
> The return value of "random( )" was unpredictable all the time, before
> and after calling the functions "srandom". Please help me how to use
> this function.
srandom initialises the random numbre generator..
this generator has a period.. the same to say that if you call the random()
or rand() it will give you the same secuence of numbers after N callings...
(in Turbo C++ N=232, i dont know in DJGPP) if one change the seed, all the
numbers of a resulting secuence will be different from a secuence resulting
with other seed..
in random(seed) seed is a parameter that is pased to functions dealing with
aleatory numbers..
if one can see the mathematical equation that these function use.. one will
find that "seed" is computed in an expression with an statistical form..
Try to change "seed" in srandom.. its is very probably that you enconunter
differences.. try also plting the results to visualy have an idea..
--
MAPE>> Miguel Angel Pérez Estrada.
Ing. Diseño y Automatización, Universidad de La Salle
mpereze AT atenea DOT lasalle DOT edu DOT co; http://www.lasalle.edu.co/~mpereze
Apartado Aéreo 3957, Santafé de Bogotá D.C., COLOMBIA.
- Raw text -