<?php class CodeGen{ private $codes = array(); public function __construct($codes) { $this->codes = $codes; } public function getRandomCode($min, $max){ $next = count($this->codes) + 1; while (count($this->codes) < $next) { $code = mt_rand($min, $max); if (!in_array($code, $this->codes)) { $this->codes[] = $code; } } } public function getLastCode(){ return end($this->codes); } } $codes = array(); $CodeGen = new CodeGen($codes); $CodeGen->getRandomCode(0, 60); print $CodeGen->getLastCode(); ?>