473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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

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.

Jul 22 '05 #1
3 22863
"ZF Tang" <zf*****@hotmail.com> wrote...
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
Jul 22 '05 #2
ZF Tang wrote:
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.j...at/MT/emt.html
Regards,

--
Lionel B

Jul 22 '05 #3
ZF Tang wrote:
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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Vamsee Krishna Gomatam | last post by:
Hello, I'm having some problems understanding Regexps in Python. I want to replace "<google>PHRASE</google>" with "<a href=http://www.google.com/search?q=PHRASE>PHRASE</a>" in a block of text....
6
by: Jon Slaughter | last post by:
I'm trying to replace some bytes in a file using fstream but all I seem to be able to do is append or 0 the file then write... Basicaly I just need to replace the first 512 bytes of the file with...
3
by: gregpinero | last post by:
I'm trying to write a little script that will have a list of word pairs which will loop through that list and replace all instances of each word with the other word. I'm very new to javascript...
3
by: Dave | last post by:
I have an Access 2K application that is distributed to about a dozen users (all with identical NT environments and identical Access versions, object libraries and service packs). I am using the VBA...
1
by: Random Task | last post by:
Can someone help me by providing an example of how to replace / with \ in a string in xslt2. The characters / and \ seem to cause me grief ... I am trying the below code currently ... Any...
4
by: ds4ff1z | last post by:
Hello, i'm looking to find and replace multiple characters in a text file (test1). I have a bunch of random numbers and i want to replace each number with a letter (such as replace a 7 with an f ...
2
by: wolverine2512 | last post by:
Hi all! I want to replace the values of QID in my datalist1 bound with the following data: Dim sqlStmnt As String = "Select QID, QUESTION from ENVIRONMENTAL_EXAM order by newid() " Dim...
2
by: pereges | last post by:
I came across a code that calculates N uniformly distributed points on the sphere. z is a random number between -1 and 1 and to calculate it we use drand48 function which returns a uniformly...
3
by: pereges | last post by:
I just tried to write a small program based on it : #include <stdio.h> #include <stdlib.h> #define PRECISION 2.82e14 double drand48(void) {
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.