| ... | ... |
@@ -687,48 +687,48 @@ |
| 687 | 687 |
/// a new random word and fill the buffer up. |
| 688 | 688 |
bool boolean() {
|
| 689 | 689 |
return bool_producer.convert(core); |
| 690 | 690 |
} |
| 691 | 691 |
|
| 692 | 692 |
///\name Nonuniform distributions |
| 693 | 693 |
/// |
| 694 | 694 |
|
| 695 | 695 |
///@{
|
| 696 | 696 |
|
| 697 | 697 |
/// \brief Returns a random bool |
| 698 | 698 |
/// |
| 699 |
/// It returns a random bool with given probability of true result |
|
| 699 |
/// It returns a random bool with given probability of true result. |
|
| 700 | 700 |
bool boolean(double p) {
|
| 701 | 701 |
return operator()() < p; |
| 702 | 702 |
} |
| 703 | 703 |
|
| 704 | 704 |
/// Standard Gauss distribution |
| 705 | 705 |
|
| 706 | 706 |
/// Standard Gauss distribution. |
| 707 | 707 |
/// \note The Cartesian form of the Box-Muller |
| 708 | 708 |
/// transformation is used to generate a random normal distribution. |
| 709 | 709 |
/// \todo Consider using the "ziggurat" method instead. |
| 710 | 710 |
double gauss() |
| 711 | 711 |
{
|
| 712 | 712 |
double V1,V2,S; |
| 713 | 713 |
do {
|
| 714 | 714 |
V1=2*real<double>()-1; |
| 715 | 715 |
V2=2*real<double>()-1; |
| 716 | 716 |
S=V1*V1+V2*V2; |
| 717 | 717 |
} while(S>=1); |
| 718 | 718 |
return std::sqrt(-2*std::log(S)/S)*V1; |
| 719 | 719 |
} |
| 720 | 720 |
/// Gauss distribution with given mean and standard deviation |
| 721 | 721 |
|
| 722 |
/// Gauss distribution with given mean and standard deviation |
|
| 722 |
/// Gauss distribution with given mean and standard deviation. |
|
| 723 | 723 |
/// \sa gauss() |
| 724 | 724 |
double gauss(double mean,double std_dev) |
| 725 | 725 |
{
|
| 726 | 726 |
return gauss()*std_dev+mean; |
| 727 | 727 |
} |
| 728 | 728 |
|
| 729 | 729 |
/// Exponential distribution with given mean |
| 730 | 730 |
|
| 731 | 731 |
/// This function generates an exponential distribution random number |
| 732 | 732 |
/// with mean <tt>1/lambda</tt>. |
| 733 | 733 |
/// |
| 734 | 734 |
double exponential(double lambda=1.0) |
| ... | ... |
@@ -800,25 +800,25 @@ |
| 800 | 800 |
double pareto(double k,double x_min) |
| 801 | 801 |
{
|
| 802 | 802 |
return exponential(gamma(k,1.0/x_min)); |
| 803 | 803 |
} |
| 804 | 804 |
|
| 805 | 805 |
///@} |
| 806 | 806 |
|
| 807 | 807 |
///\name Two dimensional distributions |
| 808 | 808 |
/// |
| 809 | 809 |
|
| 810 | 810 |
///@{
|
| 811 | 811 |
|
| 812 |
/// Uniform distribution on the full unit circle |
|
| 812 |
/// Uniform distribution on the full unit circle |
|
| 813 | 813 |
|
| 814 | 814 |
/// Uniform distribution on the full unit circle. |
| 815 | 815 |
/// |
| 816 | 816 |
dim2::Point<double> disc() |
| 817 | 817 |
{
|
| 818 | 818 |
double V1,V2; |
| 819 | 819 |
do {
|
| 820 | 820 |
V1=2*real<double>()-1; |
| 821 | 821 |
V2=2*real<double>()-1; |
| 822 | 822 |
|
| 823 | 823 |
} while(V1*V1+V2*V2>=1); |
| 824 | 824 |
return dim2::Point<double>(V1,V2); |
0 comments (0 inline)