An alternative, lazy approach would be to use
Date::Manip. It makes formatting a little easier:
use Date::Manip;
sub fakedate {
my ($lower_bound, $upper_bound) = @_;
my $timestamp = $lower_bound + int (rand $upper_bound - $lower_bo
+und +1);
return UnixDate( "epoch $timestamp", "%d-%m-%Y %H:%M:%S" );
}
Update: okay, I just learned another thing: Date::Manip is slow. Very ;-) I used Benchmark to compare
arturo's fakedate with mine:
Benchmark: timing 1000 iterations of fakedate_a, fakedate_mk...
fakedate_a: 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU) @ 33333.33/s (n=1000)
(warning: too few iterations for a reliable count)
fakedate_mk: 13 wallclock secs (12.76 usr + 0.09 sys = 12.85 CPU) @ 77.82/s (n=1000)
Thanks to
arturo and
OeufMayo for pointing this.
-
marcink
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.