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

Posted by windandwaves on 11/18/88 11:42

windandwaves wrote:
> Hi Folk
>
> I want a random list of numbers between 0 and 58 where each number
> can only occur once. I have written this ($f is an array):
>
> for($i = 0; $i < 13; $i++) {
> $rand[$i] = mt_rand(0,count($f));
> }
>
> what else do I need?
>
> TIA
>
>> Nicolaas

This is what I came up with:

for($i = 0; $i < 12; $i++) {
$r[$i] = mt_rand(0,count($f));
for($j = ($i - 1); $j > -1; $j--) {
if($r[$j] == $r[$i]) {
$i = 0;
}
}
}
but it does not seem to work

Any suggestions?

TIA

> Nicolaas

 

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

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