RE: [PHP] Picking random numbers

2001-08-21 Thread Dave
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

RE: [PHP] Picking random numbers

2001-08-20 Thread Jason Murray
OK I want to pick 5 random numbers from 1 to 200. Easy. They must all be different. Not so easy. ? srand ((double) microtime() * 100); while (count($selectednumbers) 5) { $randomnumber = rand(1, 200); if (!in_array($randomnumber, $selectednumbers)) {

RE: [PHP] Picking random numbers

2001-08-20 Thread Maxim Maletsky
Jason gave you a better way to do so, but if you want a readable one, then this code might work for you: ? function get_rand_array($from=0, $to=0, $keys=0) { $rand = Array(); if(!$keys) Return $rand; if($keys=($to-$from)) { Return $rand; // Doesn't make much sense, does