mt_rand not at all random?

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

    mt_rand not at all random?

    Hi,

    The following script:

    <?php echo mt_rand();?>

    always outputs "1755202938 " on my machine. I'm running PHP 4.2.3 under
    Windows XP.

    According to the docs:
    "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."

    So why the non-random behavior?
    - Kevin


  • Alvaro G Vicario

    #2
    Re: mt_rand not at all random?

    *** Kevin Lin wrote/escribió (Thu, 07 Oct 2004 01:20:32 GMT):[color=blue]
    > <?php echo mt_rand();?>
    >
    > always outputs "1755202938 " on my machine. I'm running PHP 4.2.3 under
    > Windows XP.
    >
    > According to the docs:
    > "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."[/color]

    It might be a bug in your release. I've tested under 4.2.2 (Red Hat Linux)
    and values are always different. Do you get random values if you do seed
    the generator?

    It could also be that it doesn't work this way under Windows but docs do
    not mention it :-?


    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- Thank you for not e-mailing me your questions
    --

    Comment

    • Kevin Lin

      #3
      Re: mt_rand not at all random?

      Follow-up for anyone who runs into this same problem:

      I upgraded to PHP 4.2.9 and the bug seems to be fixed.

      "Kevin Lin" <kevin@wx3REMOV E4SPAM.com> wrote in message
      news:AR09d.2009 76$D%.61311@att bi_s51...[color=blue]
      > Hi,
      >
      > The following script:
      >
      > <?php echo mt_rand();?>
      >
      > always outputs "1755202938 " on my machine. I'm running PHP 4.2.3 under
      > Windows XP.
      >
      > According to the docs:
      > "As of PHP 4.2.0, there is no need to seed the random number generator[/color]
      with[color=blue]
      > srand() or mt_srand() as this is now done automatically."
      >
      > So why the non-random behavior?
      > - Kevin
      >
      >[/color]


      Comment

      Working...