codice:
class UniqueRandom {
	
	var $__container = Array();

	function UniqueRandom( $n, $tot ) {
		$this->__addNum( $n, $tot );
	}
	
	function get() {
		return $this->__container;
	}

	function __addNum( &$n, &$tot ) {
		srand( (double) microtime() * 1234567 );
		for( $a = 0; $a < $n; $a++ ) {
			$num = &rand( 1, $tot );
			if( in_Array( $num, $this->__container ) ) {
			        $this->__addNum( $n, $tot );
			        break;
			}
			else {
				array_push( $this->__container, $num );
				if( count( $this->__container ) == $n ) {
					break;
				}
			}
		}
	}
}

$random = &new UniqueRandom( 2, 4 );
var_dump( $random->get() );