Newzpile v3.0

August 6, 2006, 10:35 pm
Newzpile
newzpile.com

Yep, its the third complete overhaul in three years, that is v3.0. Wrote the new system from scratch, new look, new userinterface, new concept :)

Unique series of random numbers

August 6, 2006, 3:44 pm
Here's a nifty function that comes handy every now and then. It generates X number of random numbers, ranging from A to B, but with no duplicates. PHP's rand() produces more duplicates than anything :)


CODE:

   // php
   // $num = number of 'numbers' to generate
   // $start = start of range
   // $end = end of range
   function get_rand($num, $start, $end) {
      $rand = array();
      $rand_temp = array();

      while(count($rand) < $num) {
         $temp = rand($start, $end);
         if(!isset($rand_temp[$temp])) {
            $rand_temp[$temp] = true;
            $rand[] = $temp;
         }
      }
      return $rand;
   }


Page :  1