You are here: Re: reproducible random number series « PHP Programming Language « IT news, forums, messages
Re: reproducible random number series

Posted by geoffp on 12/14/60 11:57

"Tim Roberts" <timr@probo.com> wrote in message
news:v8gpf211m537rbitnonp10j935vetoenfd@4ax.com...
> "geoffp" <fwerfrf@jhgjhfggb.com> 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.
>
> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация