# HG changeset patch # User alpar # Date 1171976482 0 # Node ID b59a17034ffaa8383f4a4ce986ec8ffd3a174aea # Parent 134639e6ea45d5eab7c69bf926b35d8c877db8f2 Some two dimensional random distribution added. They should be revised. diff -r 134639e6ea45 -r b59a17034ffa lemon/random.h --- a/lemon/random.h Tue Feb 20 12:55:37 2007 +0000 +++ b/lemon/random.h Tue Feb 20 13:01:22 2007 +0000 @@ -69,6 +69,7 @@ #include #include +#include ///\ingroup misc ///\file ///\brief Mersenne Twister random number generator @@ -742,11 +743,66 @@ /// 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); + } + + ///@} };