Created
August 29, 2012 10:27
-
-
Save mmriis/3510036 to your computer and use it in GitHub Desktop.
Random point in time between two dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Smooth, but you don't have very many options for fine tuning the result. But I love that it's very compact and simple! 👍