Function generating Unique Random Values Array
<p>As Mysql <code>rand()</code> is time consuming I am using alternate way using Mysql <code>max()</code> and PHP. I wrote this code for fetching random product_id's:</p>

<pre><code>function RandomUniqueArray($min,$max,$limit){

    $random_array = array();
    if(isset($limit) &amp;&amp; is_numeric($limit)){
        for($i=0;$i&lt;$limit;){
            $rand_val = mt_rand($min, $max);
            if(!in_array($rand_val, $random_array)){
                $random_array[] = $rand_val;
                $i++;
            }
        }
    }
    return $random_array;
}
</code></pre>

<p>This works fine as I want each time it gives different result set with different unique values but it takes 6.232 micro seconds.
Ohter I got by Google is:</p>

<pre><code>$random_array = array_rand(array_fill($min,$max, true),$limit);
</code></pre>

<p>with takes only 0.101 microseconds but its result set is repeated means. Unique values array is fine but whole set is repeated. Why is it so???</p>

<p>I called both of these by one by one as</p>

<pre><code>$random_array = RandomUniqueArray(1,64000,4);
</code></pre>

<p>And</p>

<pre><code>$random_array = array_rand(array_fill(1,64000, true),4);
</code></pre>

<p>Thank you.</p>
