473,407 Members | 2,320 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,407 software developers and data experts.

PRNG Algorithm for RAN()


Does anybody know what pseudo-random number generator was used to implement
the RAN() function in the C standard math library? Knuth couldn't have
gone so far as to implement a quadratic congruential method, right? Is it
yet another implementation of the much reviled RANDU?
Nov 13 '05 #1
4 4054

John Schutkeker <js****************@cs.com> wrote in message
news:Xn******************************@205.188.138. 161...

Does anybody know what pseudo-random number generator was used to implement the RAN() function in the C standard math library?
There isn't a single one. Each implementation is free
to use its own version, as long as its behavior meets
specifications.
Knuth couldn't have
gone so far as to implement a quadratic congruential method, right?
I don't know, why not look it up?
Is it
yet another implementation of the much reviled RANDU?


The C standard does not specify which algorithm be used
by the standard library function 'rand()'.

-Mike

Nov 13 '05 #2
John Schutkeker <js****************@cs.com> wrote:
Does anybody know what pseudo-random number generator was used to implement
the RAN() function in the C standard math library?
There is no RAN() function in the C library (and if there were, that
all-caps name would be a bad idea). The Standard RNG function is called
rand(). rand() is not in the math library, nor in the maths headers, but
in <stdlib.h> and in "the" library. There is no required algorithm for
rand(); all it has to do is provide pseudo-random numbers.
Knuth couldn't have
gone so far as to implement a quadratic congruential method, right?


Knuth has nothing to do with the ISO C Standard library (unless he is on
the ISO C Committee, which I think he isn't, BICBW), and he certainly
has not implemented anything that can be called "the" Standard library.

All the Standard requires is that
- rand() returns a sequence of PRNs, between 0 to RAND_MAX inclusive;
- no library function shall call rand() (as far as the user can detect);
- RAND_MAX is at least 32767;
- srand() can be used to initialise rand()'s seed.

Nothing else is required. An example is given as to how rand() _could_
be implemented, but that's all it is: an example.

Richard
Nov 13 '05 #3
John Schutkeker <js****************@cs.com> writes:
Does anybody know what pseudo-random number generator was used to implement
the RAN() function in the C standard math library? Knuth couldn't have
gone so far as to implement a quadratic congruential method, right? Is it
yet another implementation of the much reviled RANDU?


Hm... well, first of all, neither RAN() nor RANDU() are in the C
standard math library. Second, Donald Knuth had nothing whatsoever to
do with the creation of the standard library, though it's conceivable
that he has written one of his own.

I would be less surprised if you had meant something like "the math
library Knuth wrote in C". I still don't know to what you would be
referring, but I don't doubt that he has written math libraries in C.

But none of this is really topical in a newsgroup which discusses only
the ISO C programming language, now is it?

-Micah
Nov 13 '05 #4

Did Ritchie, or whoever wrote this routine, ever publish a justification
for the constant "1103515245." I guess the whole trick to writing a good
LCG is to find the best possible value of that constant. There's obviously
nothing special about the built in seed, "12345."

"David A" <no*****@replytogroup.com> wrote in
news:R5*****************@news-server.bigpond.net.au:
unsigned long _Randseed = 1;

int (rand)(void)
{
_Randseed = _Randseed * 1103515245 + 12345;
return ((unsigned int)(_Randseed >> 16) & RAND_MAX);
}


Nov 13 '05 #5

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

Similar topics

7
by: Protoman | last post by:
I need to write a cryptographically secure pseudorandom number generator for a crypto app I'm writing; if you could give me some example code, that'd be great. Thanks for the help!!!
28
by: joshc | last post by:
If I have an array of data that I know to be sorted in increasing order, and the array is less than 50 elements, and I want to find the first element greater than a certain value, is a simple...
31
by: pinkfloydhomer | last post by:
Using rand() in and old version og gcc, and using Tausworth's method, I calculated the frequency of 0 or 1 in the first digit like this: int hist = {0,0}; for (i = 0; i < 100000; ++i) {...
55
by: copx | last post by:
Can anyone point me to a simple, fast RRNG function to generate random ints within a specified range? It is important that each value within the range has the same probability (uniform...
0
by: Adem24 | last post by:
I put the CMWC4096 PRNG of Prof. Marsaglia into a simple C++ class. It works as intended, ie. as a 32-bit PRNG. But my question is: what must be changed in the code to make an LCG of it? <...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
0
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...

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.