rnd.hpp ctime /usr/include/gecode/kernel.hh Gecode::Rnd Gecode::Rnd::IMP Gecode /*-*-mode:C++;c-basic-offset:2;indent-tabs-mode:nil-*-*/ /* *Mainauthors: *ChristianSchulte<schulte@gecode.org> * *Copyright: *ChristianSchulte,2008 * *Lastmodified: *$Date:2012-09-0711:29:57+0200(Fri,07Sep2012)$by$Author:schulte$ *$Revision:13061$ * *ThisfileispartofGecode,thegenericconstraint *developmentenvironment: *http://www.gecode.org * *Permissionisherebygranted,freeofcharge,toanypersonobtaining *acopyofthissoftwareandassociateddocumentationfiles(the *"Software"),todealintheSoftwarewithoutrestriction,including *withoutlimitationtherightstouse,copy,modify,merge,publish, *distribute,sublicense,and/orsellcopiesoftheSoftware,andto *permitpersonstowhomtheSoftwareisfurnishedtodoso,subjectto *thefollowingconditions: * *Theabovecopyrightnoticeandthispermissionnoticeshallbe *includedinallcopiesorsubstantialportionsoftheSoftware. * *THESOFTWAREISPROVIDED"ASIS",WITHOUTWARRANTYOFANYKIND, *EXPRESSORIMPLIED,INCLUDINGBUTNOTLIMITEDTOTHEWARRANTIESOF *MERCHANTABILITY,FITNESSFORAPARTICULARPURPOSEAND *NONINFRINGEMENT.INNOEVENTSHALLTHEAUTHORSORCOPYRIGHTHOLDERSBE *LIABLEFORANYCLAIM,DAMAGESOROTHERLIABILITY,WHETHERINANACTION *OFCONTRACT,TORTOROTHERWISE,ARISINGFROM,OUTOFORINCONNECTION *WITHTHESOFTWAREORTHEUSEOROTHERDEALINGSINTHESOFTWARE. * */ #include<ctime> namespaceGecode{ classRnd:publicSharedHandle{ private: classIMP:publicSharedHandle::Object{ public: Support::RandomGeneratorrg; IMP(unsignedints); virtual~IMP(void); GECODE_KERNEL_EXPORT virtualSharedHandle::Object*copy(void)const; }; public: Rnd(void); GECODE_KERNEL_EXPORTRnd(unsignedints); Rnd(constRnd&r); GECODE_KERNEL_EXPORT voidseed(unsignedints); voidtime(void); voidhw(void); unsignedintseed(void)const; unsignedintoperator ()(unsignedintn); boolinitialized(void)const; }; forceinline Rnd::IMP::IMP(unsignedints) :rg(s){} forceinline Rnd::IMP::~IMP(void){} forceinline Rnd::Rnd(void){} forceinline Rnd::Rnd(constRnd&r) :SharedHandle(r){} inlinevoid Rnd::time(void){ seed(static_cast<unsignedint>(::time(NULL))); } inlinevoid Rnd::hw(void){ seed(Support::hwrnd()); } forceinlineunsignedint Rnd::seed(void)const{ constIMP*i=static_cast<constIMP*>(object()); returni->rg.seed(); } forceinlineunsignedint Rnd::operator ()(unsignedintn){ IMP*i=static_cast<IMP*>(object()); returni->rg(n); } forceinlinebool Rnd::initialized(void)const{ returnobject()!=NULL; } } //STATISTICS:kernel-other