Ensuring unique random number from a returned method

Hey all,

I have this:

def initialize
@a = []

def create_site!

 puts "New Site"
 50.times do |number|
   site = @sites.sample
   site_num = ensure_unique(site.site_num + random(001,999).to_s)
   puts site_num.length
   puts site_num.is_a?(String)
   site = site! :site => site, :site_num => site_num


def ensure_unique(num)
 @a << num
 return num if [email protected]? num

The above raises an exception:

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.length

What is the best way to ensure unique random number being returned from
a method?

Thanks for response