PRNG Algorithm for RAN()

Discussion in 'C Programming' started by John Schutkeker, Jul 4, 2003.

  1. 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?
    John Schutkeker, Jul 4, 2003
    #1
    1. Advertising

  2. John Schutkeker

    Mike Wahler Guest

    John Schutkeker <> wrote in message
    news:Xns93ADD8BBF5B70jschutkekercscom@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
    Mike Wahler, Jul 4, 2003
    #2
    1. Advertising

  3. John Schutkeker

    Richard Bos Guest

    John Schutkeker <> 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
    Richard Bos, Jul 4, 2003
    #3
  4. John Schutkeker

    Micah Cowan Guest

    John Schutkeker <> 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
    Micah Cowan, Jul 5, 2003
    #4
  5. 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" <> wrote in
    news:R5cNa.523$:

    > unsigned long _Randseed = 1;
    >
    > int (rand)(void)
    > {
    > _Randseed = _Randseed * 1103515245 + 12345;
    > return ((unsigned int)(_Randseed >> 16) & RAND_MAX);
    > }
    John Schutkeker, Jul 6, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jean-Michel Besnard

    init and set state of PRNG with VC++

    Jean-Michel Besnard, Jul 27, 2004, in forum: C++
    Replies:
    0
    Views:
    608
    Jean-Michel Besnard
    Jul 27, 2004
  2. Francois Grieu

    Re: C code for pure float PRNG

    Francois Grieu, Feb 5, 2004, in forum: C Programming
    Replies:
    0
    Views:
    646
    Francois Grieu
    Feb 5, 2004
  3. Good binary PRNG

    , May 15, 2006, in forum: C Programming
    Replies:
    31
    Views:
    985
    CBFalconer
    May 19, 2006
  4. Protoman

    PRNG writing

    Protoman, Sep 13, 2005, in forum: C++
    Replies:
    7
    Views:
    760
    Dave Rahardja
    Sep 14, 2005
  5. copx

    simple PRNG?

    copx, Mar 21, 2008, in forum: C Programming
    Replies:
    75
    Views:
    2,917
    Richard
    Mar 29, 2008
Loading...

Share This Page