Skip to content

Instantly share code, notes, and snippets.

@mmriis
Created August 29, 2012 10:27
Show Gist options
  • Save mmriis/3510036 to your computer and use it in GitHub Desktop.
Save mmriis/3510036 to your computer and use it in GitHub Desktop.
Random point in time between two dates
class Time
def self.random(t1, t2)
int = t2.to_i - t1.to_i
at(t1.to_i + rand(int+1))
end
end
Time.random Time.now, Time.parse("2012/12/31")
=> Tue Nov 06 10:25:17 +0100 2012
@ekampp
Copy link

ekampp commented Aug 29, 2012

Smooth, but you don't have very many options for fine tuning the result. But I love that it's very compact and simple! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment