Changeset 3099 in Sophya for trunk/SophyaLib/BaseTools/srandgen.c


Ignore:
Timestamp:
Nov 2, 2006, 3:37:05 PM (19 years ago)
Author:
ansari
Message:

Ajout PoissRand() + classe RandomGenerator / doc ds srandgen.h .cc , Reza 02/11/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/srandgen.c

    r3074 r3099  
    243243}
    244244
     245/*! \ingroup  BaseTools
     246  \brief Poisson random number generator.
     247 
     248  Return an integer value (>=0) corresponding a Poisson distribution with mean \b mu.
     249  \warning NOT the most efficient way of generating a large series of numbers
     250  with the SAME mean
     251*/
     252int PoissRand(double mu)
     253{
     254  double pp,ppi;
     255  ppi = pp = exp(-mu);
     256  double x = drand01();
     257  int n = 0;
     258  while (x > ppi) {
     259    n++;
     260    pp = mu*pp/(double)n;
     261    ppi += pp;
     262  }
     263  return n;
     264}
     265
    245266/*=========================================================================*/
    246267/*
     
    250271        sigma "s" la distribution est limitee entre am +/- GAU_RANGE (obsolete).
    251272--
     273*/
     274/*! \ingroup  BaseTools
     275 \brief OBSOLETE (gaussian random number generator)
    252276*/
    253277double GauRnd1(double am, double s)
     
    371395}
    372396
     397
     398/*!
     399  \ingroup  BaseTools
     400  \class SOPHYA::RandomGenerator
     401  \brief Random number generator
     402 
     403  This is a class with static methods, providing an alternative interface
     404  to random number generations functions declared in srandgen.h.
     405
     406  \sa frand01 drand01 frandpm1 drandpm1
     407  \sa GauRnd PoissRand
     408  \sa Ini_Ranf_Quick Ini_Ranf Get_Ranf Auto_Ini_Ranf
     409*/
     410
    373411/*==========================================================================*/
    374412/*
Note: See TracChangeset for help on using the changeset viewer.