Reply to Re: Random Number Excluding Specified Value in Array

Your name:

Reply:


Posted by Rik on 07/17/06 20:10

AP wrote:
> Hello
> Any suggestions on the most efficient way to generate a random number
> from a range that will not return values specified in an array?


Euhm, I am not really sure what you mean. Like this?

For integers:
function
rand_number_without_certain_values_for_some_reason($start,$end,$not){
$i = 0;
do{
$i++;
if($i > 5000) return false;
$int = mt_renc($start,$end);
} while (is_array($not) && in_array($int,$not));
return $int;
}

Had to build in safety (the $i) to avoid endless looping when using
something like (1,4,array(range(1,4)))

Grtz,
--
Rik Wasmus

[Back to original 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

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