in reply to Random day of a year

So here's a little one-liner

That's rather large one-liner.

Simpler:

perl -MDateTime -le'$d = DateTime->new(year=>$ARGV[0]); $d->add(days => rand($d->is_leap_year?366:365)); print $d->ymd' year

It would probably be better if you returned a day no later than the current month & day to avoid changing your age.

Replies are listed 'Best First'.
Re^2: Random day of a year
by grizzley (Chaplain) on Feb 20, 2009 at 09:40 UTC
    And if we don't care about last day in leap year (imho the result is random enough), it can be true one-liner:
    perl -MDateTime -le 'print DateTime -> new(year=>$ARGV[0]) -> add(days +=>rand(365)) -> ymd' 2013