mt_rand not at all random?

This is a discussion on mt_rand not at all random? within the PHP Language forums, part of the PHP Programming Forums category; Hi, The following script: <?php echo mt_rand();?> always outputs "1755202938" on my machine. I'm running ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-07-2004
Kevin Lin
 
Posts: n/a
Default 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


Reply With Quote
  #2 (permalink)  
Old 10-07-2004
Alvaro G Vicario
 
Posts: n/a
Default Re: mt_rand not at all random?

*** Kevin Lin wrote/escribió (Thu, 07 Oct 2004 01:20:32 GMT):
> <?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."


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
--
Reply With Quote
  #3 (permalink)  
Old 10-07-2004
Kevin Lin
 
Posts: n/a
Default 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@wx3REMOVE4SPAM.com> wrote in message
news:AR09d.200976$D%.61311@attbi_s51...
> 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
>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0