473,387 Members | 3,787 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,387 software developers and data experts.

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 5885
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***********@physik.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***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de

Nov 14 '05 #3
In article <cc**********@news1.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***********@physik.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*********@FOOverizonBAR.net> wrote in message
news:MP************************@news.verizon.net.. .
In article <cc**********@news1.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
Yes I inspected rand.c it seems it has special functions for generating it's
own random numbers based on the random numbers in the file randfile...

The random numbers of randfile are first read in a lookup table and then
later used :)

The following projects/executables are compiling/building to executables:

1. Decode.exe
2. Encode.exe
3. Extract.exe
4. MakeGen.exe
5. MakeLDPC <- fails, needs nrand48()
6. MakePCHK.exe
7. Mod2ConvertTest.exe <- fails, needs nrand48()
8. Mod2DenseTest.exe
9. Mod2SparseTest.exe
10. PrintGen.exe
11. PrintPCHK.exe
12. RandSrc.exe <- fails, needs nrand48()
13. RandTest.exe <- fails, needs nrand48()
14. Transmit.exe <- fails, needs nrand48()
15. Verify.exe

I am not sure how important MakeLDPC is at this point...

Transmit seems also pretty important for introducing noise...

Bye,
Skybuck.
Nov 14 '05 #11
In article <cc**********@news2.tilbu1.nb.home.nl>, no****@hotmail.com says...

"Randy Howard" <ra*********@FOOverizonBAR.net> wrote in message
news:MP************************@news.verizon.net.. .
In article <cc**********@news1.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]."


I don't see any reason why not. The source is freely available on the web,
check it out and see for yourself.

--
Randy Howard
To reply, remove FOOBAR.
Nov 14 '05 #12
"Skybuck Flying" <no****@hotmail.com> wrote in message news:<cc**********@news1.tilbu1.nb.home.nl>...
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.


You are doing a thing horribly wrong. Visual C++ Compiler has both an
ANSI confirming C Compiler as well as C++ Compiler.It relies on the
extension of the source file, which one is invoked by 'cl.exe' .So
before compiling your nrandxx Source file of GNU Win32, please do
change the file extension to *.c

The MSDN Library for VC++ mentions this point !!

BTW The C Compiler in VC++ supports the old K&R style of function
definition.Here it gave you error because your file extension was
*.cpp and this invoked the C++ cimpiler, which does not support old
K&R definition style.

HTH
Nitin Bhardwaj
Nov 14 '05 #13

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

Similar topics

6
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
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...
10
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); ...
21
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
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...
14
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...
7
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....
2
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.