can I replace drand48() and srand48() with random()?

Z

ZF Tang

Hi, guys.
I'm compiling a c++ file in cygwin.
drand48() and srand48() are used in this file. But there is no definition
for them in stdlib.h. Can I replace them with random()? If no, is there any
other approach to solve this problem?

I'm not familiar with Unix/Linux-like environments. Any help will be
appreciate very much.
 
V

Victor Bazarov

ZF Tang said:
I'm compiling a c++ file in cygwin.
drand48() and srand48() are used in this file. But there is no definition
for them in stdlib.h. Can I replace them with random()? If no, is there
any
other approach to solve this problem?

The answer is 'no', AFA C++ is concerned because there is no "random" in
C++.
There is 'rand' and 'srand', but they may not be what you need because the
pseudo-random numbers may be of lower range than 48 bits (I assume that it's
what '48' means in 'drand48')
I'm not familiar with Unix/Linux-like environments. Any help will be
appreciate very much.

Try comp.os.linux.development.apps newsgroup.

Of course, you can always pick up a pseudo-random number generators off
the Web of basically any resolution and quality.

Victor
 
L

Lionel B

ZF said:
Hi, guys.
I'm compiling a c++ file in cygwin.
drand48() and srand48() are used in this file. But there is no
definition for them in stdlib.h. Can I replace them with
random()? If no, is there any other approach to solve this problem?

I'm not familiar with Unix/Linux-like environments. Any help will
be appreciate very much.

It's probably safe to say that most implementations of rand(), random()
and drand48() are deeply duff as regards the quality of random deviates
generated and often have unacceptably short "periods" (the number of
random numbers produced until the sequence repeats).

My recommendation for pseudo-random number generation would be the
well-known "Mersenne Twister" RNG. It is tried and tested, performs
well on various benchmarks of "randomness", has a very long period and
is also fast. More information and code is available at:

http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
Regards,
 
A

Ares Lagae

ZF said:
Hi, guys.
I'm compiling a c++ file in cygwin.
drand48() and srand48() are used in this file. But there is no definition
for them in stdlib.h. Can I replace them with random()? If no, is there
any other approach to solve this problem?

I'm not familiar with Unix/Linux-like environments. Any help will be
appreciate very much.

replace srand48(seed) by srand(seed)
replace drand48() by (double(rand()) / RAND_MAX)

Ares
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top