Question : Need 4 Unique numbers between 1 and 14

Hi I have a piece of code which selects 4 random numbers between 1 and 14 which is then used in a switch statement so images change every time the page is refreshed. The problem is I get repeat numbers within the 4 so I have duplicate images, what do I need to change in the code to stop this happening?

Here is the code without the switch statement :

$total=4;
$min=1;
$max=14;
$rand = array();
while (count($rand) < $total ) {
    $r = mt_rand($min,$max);
    if ( !in_array($r,$rand) ) {
        $rand[] = $r;       
            }      
            }      

 Thanks for the help

Answer : Need 4 Unique numbers between 1 and 14

Tidied up version of the above. The advantage of this method is that you will not get any repeats until all the numbers have come up. It also avoids generating numbers that don't get used (eg. Think of a number...no, not that one...or that one... etc).
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
<?php
session_start();
$min = 1; $max = 14; $count = 4;

function getRandomNumbers($count, $min, $max, &$pool)
{
	if(!isset($pool) || count($pool) < $count)
	{
		$pool = range($min, $max);
		shuffle($pool);
	}
	for($c=$count;$c>0;$c--) $numbers[] = array_pop($_SESSION['pool']);
	return $numbers;
}

echo '<p>4 Numbers: '.implode(', ', getRandomNumbers($count, $min, $max, $_SESSION['pool'])).'</p>';
Random Solutions  
 
programming4us programming4us