473,809 Members | 2,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UNIX's nrand48() routine for Windows/Visual C/C++ 6.0 ?

Hello,

I have a little piece of C source code which was probably made on a UNIX
system.

I would like to try and compile/build this source code on/for Windows XP
with Visual C/C++ 6.0.

The problem is with nrand48(). Apperently the UNIX system has this routine
nrand48() in <stdlib.h>

Apperently Visual C/C++ 6.0 doesn't have this routine in it's library ?

I have no further idea how to program works so I would like to keep changes
to a minimum.

So the question becomes:

What is the best replacement for nrand48() for Visual C/C++ 6.0 ?

Bye,
Skybuck.
Nov 14 '05 #1
12 5943
Skybuck Flying <no****@hotmail .com> wrote:
I have a little piece of C source code which was probably made on a UNIX
system.
I would like to try and compile/build this source code on/for Windows XP
with Visual C/C++ 6.0.
The problem is with nrand48(). Apperently the UNIX system has this routine
nrand48() in <stdlib.h>
Apperently Visual C/C++ 6.0 doesn't have this routine in it's library ?
I have no further idea how to program works so I would like to keep changes
to a minimum.
So the question becomes:
What is the best replacement for nrand48() for Visual C/C++ 6.0 ?


Dangerously near to off-topic;-) If RAND_MAX is 2147483647 (2^31 - 1)
on your system you can probably replace nrand48() by the standard C
function rand() without any changes (unless the algorithms used in the
program rely also on some other properties of the nrand48() function,
see

http://www.opengroup.org/onlinepubs/...s/drand48.html

Otherwise you have to look out for some other function that returns
uniformely distributed pseudo-random numbers in the interval [0,2^31),
I guess someone in a MS-programming group will know what to use.

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #2

<Je***********@ physik.fu-berlin.de> wrote in message
news:2k******** ****@uni-berlin.de...
Skybuck Flying <no****@hotmail .com> wrote:
I have a little piece of C source code which was probably made on a UNIX
system.
I would like to try and compile/build this source code on/for Windows XP
with Visual C/C++ 6.0.
The problem is with nrand48(). Apperently the UNIX system has this routine nrand48() in <stdlib.h>
Apperently Visual C/C++ 6.0 doesn't have this routine in it's library ?
I have no further idea how to program works so I would like to keep changes to a minimum.
So the question becomes:
What is the best replacement for nrand48() for Visual C/C++ 6.0 ?
Dangerously near to off-topic;-) If RAND_MAX is 2147483647 (2^31 - 1)
on your system you can probably replace nrand48() by the standard C
function rand() without any changes (unless the algorithms used in the
program rely also on some other properties of the nrand48() function,
see

http://www.opengroup.org/onlinepubs/...s/drand48.html

Otherwise you have to look out for some other function that returns
uniformely distributed pseudo-random numbers in the interval [0,2^31),
I guess someone in a MS-programming group will know what to use.


Yes, I believe the program relies on nrand48 special properties...

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de

Nov 14 '05 #3
In article <cc**********@n ews1.tilbu1.nb. home.nl>, no****@hotmail. com says...
What is the best replacement for nrand48() for Visual C/C++ 6.0 ?


As is almost always the case, for standards compliant code, use rand/srand,
or if you want a guarantee on the quality of a PRNG, use one known to be
both portable and of sufficient quality. "Mersenne Twister" is a good
place to start.
--
Randy Howard
To reply, remove FOOBAR.
Nov 14 '05 #4
Skybuck Flying <no****@hotmail .com> wrote:
<Je***********@ physik.fu-berlin.de> wrote in message
news:2k******** ****@uni-berlin.de...
Skybuck Flying <no****@hotmail .com> wrote:
> What is the best replacement for nrand48() for Visual C/C++ 6.0 ?
Dangerously near to off-topic;-) If RAND_MAX is 2147483647 (2^31 - 1)
on your system you can probably replace nrand48() by the standard C
function rand() without any changes (unless the algorithms used in the
program rely also on some other properties of the nrand48() function,
see

http://www.opengroup.org/onlinepubs/...s/drand48.html

Otherwise you have to look out for some other function that returns
uniformely distributed pseudo-random numbers in the interval [0,2^31),
I guess someone in a MS-programming group will know what to use.

Yes, I believe the program relies on nrand48 special properties...


You mean that it uses a linear congruential algorithm and 48-bit
integer arithmetic, so it is not just used as a normal generator
of 32-bit pseudo-random numbers but depends on the exact sequence
the numbers are produced? In that case you may have to write your
own version, the algorithm is described on the page with the URL
I posted.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #5

<Je***********@ physik.fu-berlin.de> wrote in message
news:2k******** ****@uni-berlin.de...
Skybuck Flying <no****@hotmail .com> wrote:
<Je***********@ physik.fu-berlin.de> wrote in message
news:2k******** ****@uni-berlin.de...
Skybuck Flying <no****@hotmail .com> wrote:
> What is the best replacement for nrand48() for Visual C/C++ 6.0 ?

Dangerously near to off-topic;-) If RAND_MAX is 2147483647 (2^31 - 1)
on your system you can probably replace nrand48() by the standard C
function rand() without any changes (unless the algorithms used in the
program rely also on some other properties of the nrand48() function,
see

http://www.opengroup.org/onlinepubs/...s/drand48.html

Otherwise you have to look out for some other function that returns
uniformely distributed pseudo-random numbers in the interval [0,2^31),
I guess someone in a MS-programming group will know what to use.

Yes, I believe the program relies on nrand48 special properties...


You mean that it uses a linear congruential algorithm and 48-bit
integer arithmetic, so it is not just used as a normal generator
of 32-bit pseudo-random numbers but depends on the exact sequence
the numbers are produced? In that case you may have to write your
own version, the algorithm is described on the page with the URL
I posted.


Well I rather not write that stuff ;) so a search with google for nrand48
implementation turned up this one

http://gnuwin32.sourceforge.net/packages/libgw32c.htm

So tomorrow I will try it out... hopefully the executables won't get to big
by including it... low on disk space ;) =D though I'll be happy if the all
compile so I can try them out ;)

Bye,
Skybuck.
Nov 14 '05 #6

"Randy Howard" <ra*********@FO OverizonBAR.net > wrote in message
news:MP******** *************** *@news.verizon. net...
In article <cc**********@n ews1.tilbu1.nb. home.nl>, no****@hotmail. com says...
What is the best replacement for nrand48() for Visual C/C++ 6.0 ?


As is almost always the case, for standards compliant code, use

rand/srand, or if you want a guarantee on the quality of a PRNG, use one known to be
both portable and of sufficient quality. "Mersenne Twister" is a good
place to start.


The lrand48() and nrand48() functions return non-negative, long integers,
uniformly distributed over the interval [0,231].

Can the "Mersenne Twister" random number generator be used to:

"return non-negative, long integers, uniformly distributed over the interval
[0,231]."

???

Bye,
Skybuck.
Nov 14 '05 #7

<Je***********@ physik.fu-berlin.de> wrote in message
news:2k******** ****@uni-berlin.de...
Skybuck Flying <no****@hotmail .com> wrote:
<Je***********@ physik.fu-berlin.de> wrote in message
news:2k******** ****@uni-berlin.de...
Skybuck Flying <no****@hotmail .com> wrote:
> What is the best replacement for nrand48() for Visual C/C++ 6.0 ?

Dangerously near to off-topic;-) If RAND_MAX is 2147483647 (2^31 - 1)
on your system you can probably replace nrand48() by the standard C
function rand() without any changes (unless the algorithms used in the
program rely also on some other properties of the nrand48() function,
see

http://www.opengroup.org/onlinepubs/...s/drand48.html

Otherwise you have to look out for some other function that returns
uniformely distributed pseudo-random numbers in the interval [0,2^31),
I guess someone in a MS-programming group will know what to use.

Yes, I believe the program relies on nrand48 special properties...


You mean that it uses a linear congruential algorithm and 48-bit
integer arithmetic, so it is not just used as a normal generator
of 32-bit pseudo-random numbers but depends on the exact sequence
the numbers are produced? In that case you may have to write your
own version, the algorithm is described on the page with the URL
I posted.


I am not sure what the program depends on. The safest bet would be to have
an nrand48() function on windows which returns exactly the same numbers as
the nrand48() function on unix.

I see a number of possibilities:

1. Find the source code for nrand48() and have it compile/work on windows.
This probably requires a lot of other source for rand48() etc...

2. Use another random number generator like "Mersenne Twister"... maybe it
can also produce:

"return non-negative, long integers, uniformly distributed over the interval
[0,2^31]."

The best thing would be if it were the same numbers but that's probably
unlikely.

Maybe the Mersenne Twister is even a better random number generator than
nrand48 ;)

3. Write an nrand48() implementation from scratch ;) <- I rather not do that
since I don't know anything about random number generators or 48 bit
arithmetic, and I suck at statistics =D

I also tried linking the library 'libgw32c.a' in visual c, but that did not
work. I think the library is not ment for visual c... maybe it's ment for
gnu c compilers.

The source code of the library 'libgw32c.a' is also available so I might
succeed in extracting the necessary code for the nrand48() functions and any
other needed function and then putting that in a seperate file ;)

I would still have to find a way to make sure that it procedures the same
numbers as on unix... I should least have some indication that it s working
correctly.

Maybe I am taking it a little bit to extremes... since I know that a c
compiler is just an implementation of the c language... and each c compiler
can have errors or produce code that proceduces different results. So in
other words a unix c program might produce other results than the same c
program on windows.

Bye,
Skybuck.

Nov 14 '05 #8
However the source code that I am trying to compile does have source code
for testing the rand functions...

So maybe that source code can detect if the rand funtions are flawed... or
bad... I am not sure... :)

The source code is located on this page:

http://www.cs.toronto.edu/pub/radfor...8/install.html

Bye,
Skybuck.
Nov 14 '05 #9
I might be that the people that made the source were pretty smart...

They generated some random numbers and stored them in a file called
'randfile'...

The source also uses a RAND_FILE define or something...

I am not sure if I should make this:

#define RAND_FILE "randfile"

or that I should use a different file to prevent the "randfile" from getting
overwritten.
Nov 14 '05 #10

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

Similar topics

6
4134
by: Matthew | last post by:
How would I go about creating a simple "hello world" program that will run in Unix. I am using MS Visual C++.
5
15645
by: Skybuck Flying | last post by:
Hi, I have one more remaining "problem" with compiling a unix source code for windows/visual c/c++ 6.0 What does the isnan routine do ? Documentation says it checks for NaN ? What does that mean ? What is a good replacement for Visual C/C++ 6.0 ?
10
2170
by: Skybuck Flying | last post by:
This is the source code for nrand48 from gnuwin32 libgw32c long int nrand48 (xsubi) unsigned short int xsubi; { long int result; (void) __nrand48_r (xsubi, &__libc_drand48_data, &result); return result; }
21
2954
by: Skybuck Flying | last post by:
I am beginning to see why microsoft did not include this nrand SHIT !!!! 1. The documentation is SHIT 2. The implementation is SHIT =D IN OTHER WORDS UNIX IS SHIT !
6
1834
by: Dan V. | last post by:
Is there a way to query a remote xml file periodically by not using web services? For Windows and Unix platforms. Is there a cheap software product that I can install on each client and my Windows 2000 server and have 'secure' network access? I would love to use VS.NET to access both windows and Unix/Linux xml files.
14
6454
by: **--> That Guy Downstairs | last post by:
What files are needed to be #included to be able to copy files to a new directory and be portable? ie. use it in Unix (SGI and Linux) or Windows 2000. #ifdefs Ok. using dirent.h on SGI, but it's not working on Windows w/ VS6.0. Thanks.
7
1987
by: yang__lee | last post by:
Hi, I have been programming c, c++ on windows. What is the difference in programming on Unix.. are there different syntaxes, functions on Unix. what are mandatory different steps on unix. Whst is the difference between programming c++ on windows and unix. Which compiler one has to use on unix.
2
1977
by: sitko | last post by:
Hi, I've not coded in C since College, and am now having to convert a VB.net app into a C program that will run on a Unix box (GNU Linux). Our development environment is pure Windows, with Visual Studio. My plan is to code this C program in a C++ Project in Visual Studio, and then ftp it over to a unix box we have access to (one of our clients boxes), and use a make file to compile it in gcc(if I remember that correctly), can anyone...
1
3840
RRick
by: RRick | last post by:
I have a unix C++ project that needs to be converted over to windows visual studio. I'm not sure of the exact version of VS, but it's a recent version, probabIy 2003 or 2005. I would like the windows directory tree to mimic the unix tree as closely as possible, but I don't want duplicate files and other inconsistencies. I have come up with an idea but I don't know how close it fits a "typical" windows project. If you know of specific...
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.