# Changeset 2374:b59a17034ffa in lemon-0.x

Ignore:
Timestamp:
02/20/07 14:01:22 (14 years ago)
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3189
Message:

Some two dimensional random distribution added.
They should be revised.

File:
1 edited

Unmodified
Added
Removed
• ## lemon/random.h

 r2372 #include #include ///\ingroup misc ///\file double exponential(double lambda=1.0) { return -log(real())/lambda; return -std::log(real())/lambda; } ///@} ///\name Two dimensional distributions /// ///@{ /// Uniform distribution on the full unit circle. dim2::Point ball2() { double V1,V2; do { V1=2*real()-1; V2=2*real()-1; } while(V1*V1+V2*V2>=1); return dim2::Point(V1,V2); } /// A kind of two dimensional Gauss distribution /// This function provides a turning symmetric two-dimensional distribution. /// Both coordinates are of standard normal distribution, but they are not /// independent. /// /// \note The coordinates are the two random variables provided by /// the Box-Muller method. dim2::Point gauss2() { double V1,V2,S; do { V1=2*real()-1; V2=2*real()-1; S=V1*V1+V2*V2; } while(S>=1); double W=std::sqrt(-2*std::log(S)/S); return dim2::Point(W*V1,W*V2); } /// A kind of two dimensional exponential distribution /// This function provides a turning symmetric two-dimensional distribution. /// The x-coordinate is of conditionally exponential distribution /// with the condition that x is positive and y=0. If x is negative and /// y=0 then, -x is of exponential distribution. The same is true for the /// y-coordinate. dim2::Point exponential2() { double V1,V2,S; do { V1=2*real()-1; V2=2*real()-1; S=V1*V1+V2*V2; } while(S>=1); double W=-std::log(S)/S; return dim2::Point(W*V1,W*V2); } ///@} };
Note: See TracChangeset for help on using the changeset viewer.