[comp.lang.c] A dumb question: How to use drand48

wyeh@goofy.eng.clemson.edu (Daniel Yeh) (12/13/90)

Hi there,

I am writing my first C program to do some simulations. The problem is that
I have no idea of using the library function drand48(). I guess I'll have
to initialize the seed before invoking drand48(), but how? Also, do I need
to pass the seed to drand48() whenever I invoke it? Would anyone out there
tell me exactly what I should do with this random number generator?

Thanks in advance!

Daniel
wyeh@eng.clemson.edu

n8743196@unicorn.cc.wwu.edu (Jeff Wandling) (12/13/90)

wyeh@goofy.eng.clemson.edu (Daniel Yeh) writes:

>I am writing my first C program to do some simulations. The problem is that
>I have no idea of using the library function drand48(). I guess I'll have
>to initialize the seed before invoking drand48(), but how? Also, do I need
>to pass the seed to drand48() whenever I invoke it? Would anyone out there
>tell me exactly what I should do with this random number generator?

>Daniel
>wyeh@eng.clemson.edu

[I'm looking at the man pages in section 3C for a Sys Vr3 system.]

... Functions srand48, seed48 and lcong48 are initialization entry points,
one of which should be invoked before either drand48, lrand48 or mrand48
is called. (Although it is not reccomended, constant default initializer
values will be supplied automatically if drand48, lrand48 or mrand48 is
called without a prior call to an initialization entry point). Functions
erand48, nrand48 and jrand48 do not require an initialization entry point
to be called first.....

[A generic seed function and its C interface]

	void srand48(seedval)
	long seedval;	            /* a long integer */

[The man page continues]

...The initializer function srand48 sets the high-order 32 bits of X(i)
to the 32 bits contained in its argument (seedval). The low-order bits
of X(i) are set to the arbitrary value 330E (base 16).

[Hope this helps.]

-- 
jeff wandling | western washington university | inet: jeff@arthur.cs.wwu.edu
cs ugrad      | bellingham, wa 98225 USA      |  n8743196@unicorn.cc.wwu.edu