Mail Archives: djgpp/1998/02/01/16:28:58
In a message dated 98-02-01 14:05:42 EST, eliz AT is DOT elta DOT co DOT il writes:
> On Sun, 1 Feb 1998 Myknees AT aol DOT com wrote:
>
> > How would it be if I include this
> > fact in the diffs, stating that seeding the function is necessary in the
> two
> > cases mentioned above. That seems like it would be helpful.
>
> Seems like a good idea. Please go ahead.
Everything below the equals line is output from diff.
--Ed (Myknees)
=========================================
*** rand.txh Mon Jul 10 01:39:56 1995
--- rand3.txh Sun Feb 1 16:15:10 1998
***************
*** 1,24 ****
@node rand, random number
! @subheading Syntax
@example
#include <stdlib.h>
int rand(void);
@end example
@subheading Description
Returns a pseudo-random number from zero to @code{RAND_MAX}.
@subheading Return Value
! The number.
@subheading Example
@example
/* random pause */
for (i=rand(); i; i--);
@end example
--- 1,48 ----
@node rand, random number
! n AT subheading Syntax
@example
#include <stdlib.h>
int rand(void);
+ void srand(unsigned _seed);
@end example
@subheading Description
Returns a pseudo-random number from zero to @code{RAND_MAX}.
+ This function has its own default seed but may also be seeded with the
+ function @code{srand} (found in the @code{rand} source file). It is
+ only necessary to use @code{srand} in the following cases:
+
+ @itemize @bullet
+
+ @item
+
+ If the pseudo-random sequence must be different each time you run the
+ program
+
+ @item
+
+ If the sequence must continue from the same place it ended on some
+ previous run
+
+ @end itemize
+
@subheading Return Value
! The pseudo-random number.
@subheading Example
@example
/* random pause */
for (i=rand(); i; i--);
+ @end example
+
+ @example
+ /* seed @code{rand} with current time */
+ srand(time(0));
@end example
- Raw text -