You are here: Re: How to access random lines in textfile « PHP Programming Language « IT news, forums, messages
Re: How to access random lines in textfile

Posted by Ewoud Dronkert on 05/24/05 14:36

On Tue, 24 May 2005 11:58:44 +0100, Matt Raines wrote:
> Reading a line at a time from the file, just update the selected line if
> floor(mt_rand(0, $currentLineNumber - 1)) is 0.

Will never get beyond first line! And if implemented properly, I don't
believe it's fair (but can't be bothered to do the math, sorry).

Neither was my suggestion by the way; every next number is totally
dependent on the previous one:

> $skip = array();
> for ( $i = 0; $i < $words; ++$i )
> {
> $r = mt_rand( 0, $lines - $words );
> $lines -= $r;
> $skip[] = $r;
> }

But it was an easy way to avoid picking the same number twice or more.


--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/

 

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

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