Changeset 3446


Ignore:
Timestamp:
Dec 2, 2015, 9:19:03 AM (6 years ago)
Author:
Peter
Message:

RNG from Geomtric Distribution. closes #837

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/rnd.cc

    r2919 r3446  
    77  Copyright (C) 2006 Jari Häkkinen
    88  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    9   Copyright (C) 2012 Peter Johansson
     9  Copyright (C) 2012, 2015 Peter Johansson
    1010
    1111  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    6363
    6464  Binomial bin(0.5, 10);
     65  Geometric geo(0.5);
     66  geo();
     67  geo(0.1);
    6568
    6669  return suite.return_value();
  • trunk/yat/random/random.cc

    r3074 r3446  
    33/*
    44  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2009, 2011, 2012, 2013 Peter Johansson
     5  Copyright (C) 2009, 2011, 2012, 2013, 2015 Peter Johansson
    66
    77  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    308308
    309309
     310  Geometric::Geometric(double p)
     311    : p_(p)
     312  {}
     313
     314
     315  unsigned long int Geometric::operator()(void) const
     316  {
     317    return gsl_ran_geometric (rng_->rng(), p_);
     318  }
     319
     320
     321  unsigned long int Geometric::operator()(double p) const
     322  {
     323    return gsl_ran_geometric (rng_->rng(), p);
     324  }
     325
     326
    310327  Poisson::Poisson(const double m)
    311328    : m_(m)
  • trunk/yat/random/random.h

    r3330 r3446  
    66/*
    77  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
    8   Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Peter Johansson
     8  Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Peter Johansson
    99
    1010  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    444444  };
    445445
     446
     447  /**
     448     @brief Geomtric Distribution
     449
     450     The number of independent trials with probability \em p until the
     451     first success.
     452
     453     Probability function \f$ p(k) = p (1-p)^(k-1) \f$
     454
     455     \since New in yat 0.14
     456  */
     457  class Geometric : public Discrete
     458  {
     459  public:
     460    /**
     461       \brief Constructor
     462
     463       \param p is probability for success in one trial
     464    */
     465    Geometric(double p);
     466
     467    /*
     468      \return a number from Geomtric distribution
     469    */
     470    unsigned long operator()(void) const;
     471
     472    /**
     473       \return a number from Geomtric distribution with success rate \a p
     474
     475       \note this operator ignores parameters set in Constructor
     476    */
     477    unsigned long operator()(double p) const;
     478
     479  private:
     480    double p_;
     481  };
     482
     483
    446484  /**
    447485     @brief Poisson Distribution
Note: See TracChangeset for help on using the changeset viewer.