[date_time] how to generate a random date?

Hi,
Does boost's date provide a random date generation?
Or somehow should I generate my own date and then pass as a parameter?
date GeneratorUtils::getRandomDate() {
int year, month ,day;
day = 1 + rand() % 29;
month = 1 + rand() % 11;
year = 1980 + rand() % 25;
date d(year, month, day);
return d;
}
currently this is my implementation, but sometimes it returns invalid month
value.
terminate called after throwing an instance of
'boost::exception_detail::clone_impl
' what(): Day of month is not valid for year
Probably because of something like 29th Feb or sth like that. I rarely saw that exception. I could modify the code easiy but I just wanted to know that if such a functionality exists? Thanks a lot, I've started to adore boost after uuid & date =) -- Saygin

On Thu, 2010-05-13 at 15:21 +0300, Saygin Arkan wrote:
Hi, Does boost's date provide a random date generation? Or somehow should I generate my own date and then pass as a parameter?
date GeneratorUtils::getRandomDate() { int year, month ,day; day = 1 + rand() % 29; month = 1 + rand() % 11; year = 1980 + rand() % 25; date d(year, month, day);
return d; }
date GeneratorUtils::getRandomDate() { return (date d(1980, 1, 1) + date_duration(rand()); } -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277 fax: 024-3608416 web: www.askesis.nl

Thanks a lot, much more efficient...
SA
On Thu, May 13, 2010 at 3:53 PM, Joost Kraaijeveld wrote: On Thu, 2010-05-13 at 15:21 +0300, Saygin Arkan wrote: Hi,
Does boost's date provide a random date generation?
Or somehow should I generate my own date and then pass as a parameter? date GeneratorUtils::getRandomDate() {
int year, month ,day;
day = 1 + rand() % 29;
month = 1 + rand() % 11;
year = 1980 + rand() % 25;
date d(year, month, day); return d;
} date GeneratorUtils::getRandomDate() { return (date d(1980, 1, 1) + date_duration(rand());
} --
Groeten, Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
web: www.askesis.nl _______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users --
H. Saygin Arkan
Tampere University of Tech.
CS / III - +358466646156

You'll probably find it more simple to generate your random date in the seconds domain, and then convert that back to a date. I don't know the specific boost function for this. Cheers Rich Internet saygenius@gmail.com Sent by: boost-users-bounces@lists.boost.org 14/05/2010 09:26 Please respond to boost-users@lists.boost.org To boost-users@lists.boost.org cc Subject Re: [Boost-users] [date_time] how to generate a random date? Thanks a lot, much more efficient... SA On Thu, May 13, 2010 at 3:53 PM, Joost Kraaijeveld < J.Kraaijeveld@askesis.nl> wrote: On Thu, 2010-05-13 at 15:21 +0300, Saygin Arkan wrote:
Hi, Does boost's date provide a random date generation? Or somehow should I generate my own date and then pass as a parameter?
date GeneratorUtils::getRandomDate() { int year, month ,day; day = 1 + rand() % 29; month = 1 + rand() % 11; year = 1980 + rand() % 25; date d(year, month, day);
return d; }
date GeneratorUtils::getRandomDate() { return (date d(1980, 1, 1) + date_duration(rand()); } -- Groeten, Joost Kraaijeveld Askesis B.V. Molukkenstraat 14 6524NB Nijmegen tel: 024-3888063 / 06-51855277 fax: 024-3608416 web: www.askesis.nl _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- H. Saygin Arkan Tampere University of Tech. CS / III - +358466646156_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users ___________________________________________________________ This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is prohibited. Please refer to http://www.bnpparibas.co.uk/en/information/legal_information.asp?Code=ECAS-8... for additional disclosures.
participants (3)
-
Joost Kraaijeveld
-
richard.carless@uk.bnpparibas.com
-
Saygin Arkan