reproducible random number series

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

    #1

    reproducible random number series

    I need to generate reproducible random number series.

    I've done the obvious - use mt_srand with the same seed. This supposedly
    will create the same series every time.

    Is this true? Its not working for me.

    By the way, seeding mt_srand with different integers doesn't necessarily
    produce different series. I've done a little testing and every pair of
    consecutive even and odd numbers produces the same series. eg. seed 0 and 1
    produce the same series, as does 10000 and 10001.

    geoffair in xgmailx xcomx


  • davie

    #2
    Re: reproducible random number series


    geoffp wrote:
    I need to generate reproducible random number series.
    >
    I've done the obvious - use mt_srand with the same seed. This supposedly
    will create the same series every time.
    >
    Is this true? Its not working for me.
    >
    By the way, seeding mt_srand with different integers doesn't necessarily
    produce different series. I've done a little testing and every pair of
    consecutive even and odd numbers produces the same series. eg. seed 0 and 1
    produce the same series, as does 10000 and 10001.
    >
    geoffair in xgmailx xcomx
    As of PHP 4.2.0, there is no need to seed the random number generator
    with srand() or mt_srand() as this is now done automatically.

    I assume you want the same series of random numbers ?
    If this is the case generate your series and save to a file

    Comment

    • Tim Roberts

      #3
      Re: reproducible random number series

      "geoffp" <fwerfrf@jhgjhf ggb.comwrote:
      >I need to generate reproducible random number series.
      >
      >I've done the obvious - use mt_srand with the same seed. This supposedly
      >will create the same series every time.
      >
      >Is this true? Its not working for me.
      Really? I did this:

      <?php
      mt_srand(1000);
      echo mt_rand(), "\n";
      echo mt_rand(), "\n";
      echo mt_rand(), "\n";
      echo mt_rand(), "\n";
      ?>

      and it produces the same sequence every time. Note that you can't rely on
      the sequence continuing across pages.
      >By the way, seeding mt_srand with different integers doesn't necessarily
      >produce different series. I've done a little testing and every pair of
      >consecutive even and odd numbers produces the same series. eg. seed 0 and 1
      >produce the same series, as does 10000 and 10001.
      You are correct. The code for mt_srand always sets the bottom bit.
      --
      - Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      • geoffp

        #4
        Re: reproducible random number series


        "Tim Roberts" <timr@probo.com wrote in message
        news:v8gpf211m5 37rbitnonp10j93 5vetoenfd@4ax.c om...
        "geoffp" <fwerfrf@jhgjhf ggb.comwrote:
        >
        >>I need to generate reproducible random number series.
        >>
        >>I've done the obvious - use mt_srand with the same seed. This supposedly
        >>will create the same series every time.
        >>
        >>Is this true? Its not working for me.
        >
        Really? I did this:
        >
        <?php
        mt_srand(1000);
        echo mt_rand(), "\n";
        echo mt_rand(), "\n";
        echo mt_rand(), "\n";
        echo mt_rand(), "\n";
        ?>
        >
        and it produces the same sequence every time. Note that you can't rely on
        the sequence continuing across pages.
        >
        >>By the way, seeding mt_srand with different integers doesn't necessarily
        >>produce different series. I've done a little testing and every pair of
        >>consecutive even and odd numbers produces the same series. eg. seed 0 and
        >>1
        >>produce the same series, as does 10000 and 10001.
        >
        You are correct. The code for mt_srand always sets the bottom bit.
        --
        - Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.
        Thanks Tim - I think I see whats happening.

        I assumed that once srand had been seeded, the series would continue for
        the whole session(I set it in the first page). From what you say I gather
        that the series ends whenever you call a page, even though its got the same
        PHP code. Then the randomiser is seeded automatically the first time its
        called - DOH!

        Geoff


        Comment

        • geoffp

          #5
          Re: reproducible random number series


          "Tim Roberts" <timr@probo.com wrote in message
          news:v8gpf211m5 37rbitnonp10j93 5vetoenfd@4ax.c om...
          "geoffp" <fwerfrf@jhgjhf ggb.comwrote:
          >
          ....
          >
          and it produces the same sequence every time. Note that you can't rely on
          the sequence continuing across pages.
          >
          >>By the way, seeding mt_srand with different integers doesn't necessarily
          >>produce different series. I've done a little testing and every pair of
          >>consecutive even and odd numbers produces the same series. eg. seed 0 and
          >>1
          >>produce the same series, as does 10000 and 10001.
          >
          You are correct. The code for mt_srand always sets the bottom bit.
          --
          - Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.
          Thanks Tim - I think I see whats happening.

          I naively assumed that once srand had been seeded, the series would
          continue for the whole session(I set it in the first page). From what you
          say I gather
          that the series ends whenever you call a page, even though its got the same
          PHP code. Then the randomiser is seeded automatically the first time its
          called - DOH!

          Geoff

          PS Some of my posts to this group don't seem to be appearing, so apologies
          if you've got this twice. I don't often use newsgroups.



          Comment

          Working...