Boost logo

Boost Users :

From: frederic.bron_at_[hidden]
Date: 2007-11-21 10:37:21


Hi,

I face a speed problem. I need a uniform distribution of integers between 0 and N, N around 10^11.
I tried 2 methods with very high speed efficiency difference (time x8). The 1st one is based on uniform_smallint (the slowest method) and the 2nd one is based on a real distribution casted to an
integer.
Is there a problem with the 2nd method which is much quicker?

Fred

common code:

typedef boost::mt19937 base_generator_type;
base_generator_type generator;
generator.seed(static_cast<unsigned int>(std::time(0))) ;

method 1 (using uniform_smallint):

boost::uniform_smallint<uint32_t> uni_dist((uint32_t)0, (uint32_t)10000000000);
boost::variate_generator<base_generator_type*, boost::uniform_smallint<uint32_t> > uni(&generator, uni_dist);
for (unsigned long k=0 ; k<100000000UL; ++k) uni() ;

method 2 (using uniform_real and casting):

boost::uniform_real<double> uni_dist(0., 100000000001.);
boost::variate_generator<base_generator_type*, boost::uniform_real<double> > uni(&generator, uni_dist);
for (unsigned long k=0 ; k<100000000UL; ++k) (uint32_t)uni() ;

F. Bron
___________________________________
Frédéric Bron (frederic.bron_at_[hidden])
Unité ALT, Alcan CRV, BP 27, 38341 Voreppe
téléphone : +33 4 76 57 81 72
télécopie : +33 4 76 57 80 99

Avis :
Ce message et toute pièce jointe sont la propriété d'Alcan et sont destinés seulement aux personnes ou à l'entité à qui le message est adressé. Si vous avez reçu ce message par erreur, veuillez le
détruire et en aviser l'expéditeur par courriel. Si vous n'êtes pas le destinataire du message, vous n'êtes pas autorisé à utiliser, à copier ou à divulguer le contenu du message ou ses pièces jointes
en tout ou en partie.

Notice:
This message and any attachments are the property of Alcan and are intended solely for the named recipients or entity to whom this message is addressed. If you have received this message in error
please inform the sender via e-mail and destroy the message. If you are not the intended recipient you are not allowed to use, copy or disclose the contents or attachments in whole or in part.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net