drand48 on Windows

drand48 srand48
drand48 vs random
c++ random
lrand48 windows
rand
c++ generate random number between 1 and 10
c++ rand 0 to 100
rand mod c

I am looking for an equivalent to drand48 on Windows. To all who do not know, the following is not equivalent:

(double)rand()/RAND_MAX;

Firstly, rand returns values including RAND_MAX Secondly, on Windows RAND_MAX=32767 which is a too short period for my application.

My purpose is to generate noise for a simulation. It is desirable to use a pseudo-random generator with the same period as drand48.

Firstly, note that you appear to be confusing the resolution with the period. On Windows, rand will return values from 0 to 32767, but this does not mean that the same values will repeat every 32768 calls. So rand should be perfectly adequate unless you need more than 16 bits of resolution. (The resolution and the period are the same in drand48, but not in all pseudorandom number generators.)

If you do not need the exact behaviour of drand48, rand_s would be the simplest option. It has a 32-bit resolution, less than drand48 but enough for most purposes. It generates a cryptographically secure random number, so there is no fixed period. One possible issue is that it will be much slower than drand48.

If you want the same behaviour of drand48, the algorithm is documented and should be easy to re-implement, or you could use the source code from FreeBSD (link to source code browser on http://fxr.watson.org/).

How to use drand48() for Windows, drand48() returns a random double in the range [0.0, 1.0). You can mimic with rand() by the expression (rand() / (RAND_MAX + 1.0)). If you don't  drand48.c: In function 'double erand48(short unsigned int*)': drand48.c:44:45: error: 'ldexp' was not declared in this scope return ldexp((double) xseed[0], -48) +

7 years late to the party. Sorry.

Gnu Scientific Library is a good solution to this problem. The library employs several high-quality generating algorithms.

https://www.gnu.org/software/gsl/doc/html/rng.html

drand48() and srand48(long) on windows. (based on Freebsd: http , drand48() and srand48(long) on windows. (based on Freebsd: drand48.c. #​define RAND48_SEED_0 (0x330e). #define RAND48_SEED_1  Re: How to use drand48 () for Windows drand48 () returns a random double in the range [0.0, 1.0). You can mimic with rand () by the expression (rand () / (RAND_MAX + 1.0)). If you don't want to use rand (), then use a pseudorandom number generator library.

It might not be an exact answer to your question, but still it is a solution. Use the CryptGenRandom(it's form the WinAPI).

Porting srand48 and drand48 of Unix like platform based source, In the source, srand48() and drand48() functions are used for radom number generation. Is there a equivalent function provided by Windows? I need to port a program initially used on Unix like platform. It's a test program. In the source, srand48() and drand48() functions are used for radom number generation. Is there a equivalent function provided by Windows? Thanks.

drand48 on Windows - windows - iOS, I am looking for an equivalent to drand48 on Windows. To all who do not know, the following is not equivalent: (double)rand()/RAND_MAX; Firstly, rand returns  You can't add it into the standard C library, unless you have access to that source code and want to find an implementation of drand48(). Here's a class library for Windows that contains drand48() - you might want to try that, although the library is large you may be able to sift through it and just remove the drand code.

MinGW, What are you trying to accomplish: why do you want drand48()? Would any random-number generator suit your purposes? Do you need one that's better than what  The drand48(), erand48(), jrand48(), lrand48(), mrand48() and nrand48() functions generate uniformly distributed pseudo-random numbers using a linear congruential algorithm and 48-bit integer arithmetic.

c++ - Why doesn't drand48() and srand48() work., c++ - Why doesn't drand48() and srand48() work. %u (35/35) Oct 06 2006 Excuse me, I am no experienced C programmer, but I really need help. Walter Bright  On Windows, rand will return values from 0 to 32767, but this does not mean that the same values will repeat every 32768 calls. So rand should be perfectly adequate unless you need more than 16 bits of resolution. (The resolution and the period are the same in drand48, but not in all pseudorandom number generators.)

Comments
  • I copied the source from glibc.
  • Here is a my implementation (also based on FreeBSD): gist.github.com/mortennobel/8665258
  • No - please don't use CryptGenRandom (or any function that returns random bytes) and then use those bytes as the byte representation of a supposedly "random" floating single or double-precision number.
  • @NikBougalis why not?
  • Because a "float" has structure (i.e. specific bits represent the mantissa and other bits the exponent) and there's no guarantee that filling those bits randomly by a stream of random bytes will produce floating-point outputs where each float is just as likely as every other.