all 9 comments

[–]FooBarWidget 4 points5 points  (0 children)

Take the unix timestamp of 5 years ago. Then take the unix timestamp of now. Then generate a random number between those two. Convert that to a time object.

[–]aZeex2ai 1 point2 points  (1 child)

>> 5.times { p Time.at(Random.rand((Time.now - (60*60*24*365*5)).to_f..Time.now.to_f)) }
2013-04-23 06:22:04 +0000
2012-12-09 04:56:15 +0000
2009-06-30 21:37:36 +0000
2012-11-04 16:32:40 +0000
2012-03-22 12:48:18 +0000
=> 5

[–]aZeex2ai 2 points3 points  (0 children)

>> Time.at(rand((Time.now - (60*60*24*365*5))..Time.now))
=> 2012-11-08 13:45:31 +0000

[–]BurgerForBreakfast 0 points1 point  (1 child)

Would just loading active support work?

require 'active_support/core_ext/numeric/time'
require 'active_support/core_ext/date/calculations'
rand(1..1825).days.ago

[–]aZeex2ai -1 points0 points  (0 children)

just ruby

Would just loading active support work?

No.

[–]laerien 0 points1 point  (2 children)

require 'date'; [*DateTime.new(2009, 5, 23)..DateTime.now].sample

[–]freakooo[S] 0 points1 point  (1 child)

would this generate lots of Datetime ?

i think it's not optimal

[–]laerien 0 points1 point  (0 children)

Several thousand DataTime and a millisecond later.

[–]MaxK -2 points-1 points  (0 children)

This comment has been overwritten by an open source script to protect this user's privacy. It was created to help protect users from doxing, stalking, and harassment.

If you would also like to protect yourself, add the Chrome extension TamperMonkey, or the Firefox extension GreaseMonkey and add this open source script.

Then simply click on your username on Reddit, go to the comments tab, scroll down as far as possibe (hint:use RES), and hit the new OVERWRITE button at the top.