You are on page 1of 2

this exaplanation is based on

youtube channel "coding


experiments".please watch that
video first then read this
document.
first of all like all C programs
we added library files.namely
'stdio.h',stdlib.h' and 'time.h'
for using standard input
output,standard library, and time
header files respectfully.in this
tutorial we will use pseudo
random number generating
algorithm .to use this algorithm
C provides two strong standard
library functions namely rand()
and srand().both have their own
works in this algorithm.rand()
function is used to generate as
much as random numbers as we
want.a disadvantage of using
rand() without srand() is that it
will always generate same numbers
every time we run the code.this
is because pseudo algorithm uses
a seed value to generate random
numbers.in this case every time
seed value is same which is it's
default value it will generate
same numbers.To overcome this
limitation we mannually setupped
seed value for algorithm.This is
done by function srand().
The parameter passed to it is the
seed value we want.IN our case we
want changing seed values so we
used time().time() function
returns current time.since time
is continuosly changing so we can
use current time as our seed
value.time() function needs a
parameter which is the base
address of a varible where we
want to save current time.We
passed simply NULL to time()
because we do not want to save
time in our code.
At last we simply printed these
numbers in a loop with standard
library function printf().

You might also like