You've gotten a few responses already... but since you didn't describe the
application, here is an alternative if you are using the random numbers to
retrieve random records from a database (postgreqsl in this example);
$query = "SELECT * FROM table ORDER BY random() LIMIT 5";
am usre the MySQL
Jason gave you a better way to do so, but if you want a "readable one", then
this code might work for you:
=($to-$from)) {
Return $rand;
// Doesn't make much sense, does it?
}
while(True) {
$tmp_num = rand($from, $to);
if($keys>sizeof($rand)) {
if(!in_array
> OK I want to pick 5 random numbers from 1 to 200. Easy.
> They must all be different. Not so easy.
This should work well enough to give you the general idea ... sorry if it
doesn't, I grabbed some old code and modified it so I didn't embarrass
myself too much by posting spaghetti code. :
3 matches
Mail list logo