Random Integers from 0 to 999

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Wojcik

    #31
    Re: Random Integers from 0 to 999


    In article <H_idnWvuAfFCe8 jfRVn-vQ@comcast.com> , Eric Sosman <esosman@acm-dot-org.invalid> writes:[color=blue]
    > Michael Wojcik wrote:[color=green]
    > >
    > > At any rate, I agree with the basic point: if you're dissatisfied, or
    > > think you might be, with rand(), better generators are not hard to
    > > come by.[/color]
    >
    > Since the quality of rand() is implementation-specific,
    > "better" is hard to justify in a universal sense.[/color]

    Sure. In this case, though, a "better" one is merely one that
    produces less dissatisfaction in the subject (since dissatisfaction
    with rand() is a precondition). Especially perverse cases aside that
    looks eminently achievable, as you yourself suggest:
    [color=blue]
    > It seems that everybody[*] eventually latches onto a favorite
    > substitute for rand().[/color]

    There you are, then. Everyone will be able to find a "better"
    substitute for rand, on the grounds that they will feel that it's
    better, and so it will displease them less. What's programming for,
    if not to console programmers?
    [color=blue]
    > My own not-so-humble opinion is that the C Standard should leave the
    > requirements on rand() as weak as they are today, but should describe
    > it as a "coarse" source of variates, suitable for "casual" use but
    > not for serious work.[/color]

    Agreed.

    --
    Michael Wojcik michael.wojcik@ microfocus.com

    What is it with this warm, quiet, nauseating bond between them?
    -- Rumiko Takahashi, _Maison Ikkoku_, trans. Mari Morimoto, adapt. Gerard
    Jones

    Comment

    • Michael Wojcik

      #32
      Re: Random Integers from 0 to 999


      In article <kfnwtrc1dkv.fs f@alumnus.calte ch.edu>, Tim Rentsch <txr@alumnus.ca ltech.edu> writes:[color=blue]
      > mwojcik@newsguy .com (Michael Wojcik) writes:
      >[color=green]
      > > Alternatively, George Marsaglia has posted code here for a couple of
      > > C implementations of Complementary-Multiply-With-Carry (CMWC) PRNGs,
      > > which though not portable (IIRC) should be easy enough to adapt to
      > > most C implementations . [snip][/color]
      >
      > The CMWC code that I was able to find (some of it in CLC postings)
      > usually used 'long long'.[/color]

      Yes, I think the version I have does too, though if memory serves
      there were no great differences in adapting it to use a pair of
      unsigned longs, if long has fewer than 64 bits. It's been a while
      since I looked at it, though.
      [color=blue]
      > By the way, I had trouble tracking down web articles on CMWC, because
      > most of the web writing on CMWC says complImentary rather than
      > complEmentary.[/color]

      Oh, well. (Perhaps it *is* "complimentary" : the multiply says
      something favorable about its operands, or happens for free. I
      suspect this is just a case of homophone confusion, though.)
      [color=blue][color=green]
      > > On a related note: there was a thread on sci.crypt not long ago
      > > regarding producing an unbiased subrange of the PRNG's range (a
      > > common task which we were recently discussing here) while consuming
      > > the minimum possible number of bits from the generator's output.[/color]
      >
      > For practical purposes I'm inclined to think it's not worth the
      > trouble.[/color]

      Probably not, though it's a fun discussion. I can see some areas
      where it might be useful, though, such as providing a deterministic-
      time unbiased generator for a real-time application or making it
      easier to blind the time and power consumption of the PRNG for crypto
      purposes.

      --
      Michael Wojcik michael.wojcik@ microfocus.com

      Duck: No secret what's worth a hoot ought to be kept quiet.
      Pogo: Secrets is usually perty doggone fascinatin'.
      Duck: Egg-zackly ... it's completely illogical to keep a secret secret.
      Pogo: An' unfair. -- Walt Kelly

      Comment

      • Richard Bos

        #33
        Re: Random Integers from 0 to 999

        websnarf@gmail. com wrote:
        [color=blue]
        > 1. The calls to rand() are not independent
        >
        > or
        >
        > 2. With a high degree of confidence you can say there is an
        > eccentricity in the distribution of the output probabilities that
        > underrepresents zero as an output.
        >
        > This actually matters to some people, and its an interesting echo to
        > the "Can you use C for mathematical purposes?" thread from earlier that
        > nobody here seems to be sensitive to the above in any way.[/color]

        I dare say that people who use C for mathematical purposes _are_ aware
        of the above, and moreover are aware that

        Anyone who considers arithmetical methods of producing
        random digits is, of course, in a state of sin.
        Alfred E. Neumann, 1951

        Richard

        Comment

        • Grumble

          #34
          Re: Random Integers from 0 to 999

          Keith Thompson wrote:
          [color=blue]
          > If an implementation' s rand() function never returns 0, the implementation
          > is either non-conforming or of poor quality.
          >
          > Do you know of an implementation in which rand() never returns 0?[/color]

          I was under the impression that the PRNG discussed in [1] had been
          used often in the old days?

          [1] "Random number generators: good ones are hard to find"


          u_0 = 1
          u_{n+1} = 16807*u_n mod (2^31-1)

          Come to think of it, an implementor could very well return u_n - 1
          and set RAND_MAX to 2^31-3...

          --
          Regards, Grumble

          Comment

          • Keith Thompson

            #35
            Re: Random Integers from 0 to 999

            rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:
            [snip][color=blue]
            > I dare say that people who use C for mathematical purposes _are_ aware
            > of the above, and moreover are aware that
            >
            > Anyone who considers arithmetical methods of producing
            > random digits is, of course, in a state of sin.
            > Alfred E. Neumann, 1951[/color]

            I dare say most of them are aware that the quotation is by John von
            Neumann, not the guy on the cover of Mad Magazine.

            (There is, of course, a connection between Mad Magazine and computer
            science; google Potrzebie Knuth for details.)

            --
            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
            San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
            We must do something. This is something. Therefore, we must do this.

            Comment

            • Richard Bos

              #36
              Re: Random Integers from 0 to 999

              Keith Thompson <kst-u@mib.org> wrote:
              [color=blue]
              > rlb@hoekstra-uitgeverij.nl (Richard Bos) writes:
              > [snip][color=green]
              > > I dare say that people who use C for mathematical purposes _are_ aware
              > > of the above, and moreover are aware that
              > >
              > > Anyone who considers arithmetical methods of producing
              > > random digits is, of course, in a state of sin.
              > > Alfred E. Neumann, 1951[/color]
              >
              > I dare say most of them are aware that the quotation is by John von
              > Neumann, not the guy on the cover of Mad Magazine.[/color]

              <g> What, me worry?
              [color=blue]
              > (There is, of course, a connection between Mad Magazine and computer
              > science; google Potrzebie Knuth for details.)[/color]

              Or buy Van der Linden's Expert C Programming.

              Richard

              Comment

              • Grumble

                #37
                Re: Random Integers from 0 to 999

                Grumble wrote:
                [color=blue]
                > Keith Thompson wrote:
                >[color=green]
                >> If an implementation' s rand() function never returns 0, the
                >> implementation is either non-conforming or of poor quality.
                >>
                >> Do you know of an implementation in which rand() never returns 0?[/color]
                >
                > I was under the impression that the PRNG discussed in [1] had been
                > used often in the old days?
                >
                > [1] "Random number generators: good ones are hard to find"
                > http://www-scf.usc.edu/~csci105/links/p1192-park.pdf
                >
                > u_0 = 1
                > u_{n+1} = 16807*u_n mod (2^31-1)
                >
                > Come to think of it, an implementor could very well return u_n - 1
                > and set RAND_MAX to 2^31-3...[/color]

                Has this implementation of rand() been used often?

                Comment

                Working...