Skip to content

Instantly share code, notes, and snippets.

@adambird
Created May 15, 2013 07:49
Show Gist options
  • Save adambird/5582273 to your computer and use it in GitHub Desktop.
Save adambird/5582273 to your computer and use it in GitHub Desktop.
Methods for generating randomised variables for testing purposes
def random_string
(0...24).map{ ('a'..'z').to_a[rand(26)] }.join
end
def random_symbol
random_string.to_sym
end
def random_integer
rand(9999)
end
def random_float
random_integer + rand
end
def random_time
(Time.now + random_integer.minutes).utc
end
def random_date
Time.new(random_time.year, random_time.month, random_time.day)
end
def random_email
"#{random_string}@#{random_domain}"
end
def random_domain
"#{random_string}.com"
end
def random_url
"http://#{random_string}.#{random_domain}/#{random_string}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment