Random number generator

Discussion in 'C++' started by ciccio, Apr 15, 2008.

  1. ciccio

    ciccio Guest

    Hi,

    Maybe slightly off topic here, but what algorithm is used for the
    implementation of rand() in <cstdlib> ?

    Or if it is not standardized (which it should), does anybody know what
    it is in g++?

    Thanks
     
    ciccio, Apr 15, 2008
    #1
    1. Advertising

  2. ciccio

    Ian Collins Guest

    ciccio wrote:
    > Hi,
    >
    > Maybe slightly off topic here, but what algorithm is used for the
    > implementation of rand() in <cstdlib> ?
    >

    See section 7.20.2.2 of the standard for a portable implementation.

    --
    Ian Collins.
     
    Ian Collins, Apr 15, 2008
    #2
    1. Advertising

  3. ciccio

    Ian Collins Guest

    Ian Collins wrote:
    > ciccio wrote:
    >> Hi,
    >>
    >> Maybe slightly off topic here, but what algorithm is used for the
    >> implementation of rand() in <cstdlib> ?
    >>

    > See section 7.20.2.2 of the standard for a portable implementation.
    >

    The C99 standard that is.

    --
    Ian Collins.
     
    Ian Collins, Apr 15, 2008
    #3
  4. ciccio

    Kai-Uwe Bux Guest

    ciccio wrote:

    > Hi,
    >
    > Maybe slightly off topic here, but what algorithm is used for the
    > implementation of rand() in <cstdlib> ?


    Not specified by the standard.


    > Or if it is not standardized (which it should),


    C++0X will have <random> with standardized algorithms.


    > does anybody know what it is in g++?


    http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/stdlib/?cvsroot=glibc

    You want to look at rand.c and random.c.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Apr 15, 2008
    #4
  5. ciccio

    James Kanze Guest

    On 15 avr, 10:57, Ian Collins <> wrote:
    > ciccio wrote:


    > > Maybe slightly off topic here, but what algorithm is used for the
    > > implementation of rand() in <cstdlib> ?


    > See section 7.20.2.2 of the standard for a portable implementation.


    That's the C standard, of course. And it's known to be a very
    poor generator.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Apr 15, 2008
    #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. Kingsley Oteng

    Random Number Generator??

    Kingsley Oteng, Apr 27, 2004, in forum: VHDL
    Replies:
    11
    Views:
    52,286
    rahul.iyer
    Aug 9, 2010
  2. tshad

    Random number/letter generator

    tshad, May 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    9,571
    tshad
    May 6, 2005
  3. Wally
    Replies:
    1
    Views:
    2,796
    pvdg42
    Mar 20, 2006
  4. globalrev
    Replies:
    4
    Views:
    778
    Gabriel Genellina
    Apr 20, 2008
  5. VK
    Replies:
    15
    Views:
    1,187
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page