You are here: Re: random without replacement « PHP Programming Language « IT news, forums, messages
Re: random without replacement

Posted by Jerry Stuckle on 10/24/09 11:42

Tyxod wrote:
> The "shuffle" thing does the work but produces an array with 58
> elements. And it works a lot faster than the recursive thing (it
> matters if the function is used more than a few times in a script).
>
> But if you need just 13 (or anything else <>58) items in the array the
> recursive function is really the only sane way to go.
>
> (of course one could "shuffle($randomstuff);" and then pick up the
> first 13 items from the resulted array, but I really dont like doing
> that)
>

Why not?

1. It's much clearer than the recursive code
2. It's faster than the recursive code

If course - it does use 156 more bytes than the recursive solution. But
the parser will probably need more than this just to handle the extra
code anyway.

Sometimes saving a few bytes just isn't worth it!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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