[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [Help-gsl] Zipf Random Number Generator

**From**: |
Michael Dürr |

**Subject**: |
Re: [Help-gsl] Zipf Random Number Generator |

**Date**: |
Fri, 30 May 2008 12:02:07 +0200 |

**User-agent**: |
Thunderbird 2.0.0.14 (X11/20080505) |

Hi Martin,
thanks for your answer!
I had a look at the algorithm and implemented the following thing:
int RNG::zipfRandom(double skew) {
double a = skew;
double b = pow(2.0, a - 1.0);
double X, T, U, V;
do {
U = randomDouble(); // produces double in range [0.0..1.0]
V = randomDouble();
X = floor(pow(U, -1.0/a - 1.0));
T = pow(1.0 + 1.0/X, a - 1.0);
} while (V*X*(T - 1.0)/(b - 1.0) > (T/b));
return static_cast<int>(X);
}
I'm not that familiar with statistics, but I need this distribution to perform
some simulations and I want to be certain about the correct application of this
function. I attached the output for zipfRandom(1.4) as pdf. Do you recognize any
error in this function?
I've got two more questions:
- I read something a bout the Zipf Exponent which I have to set to 0.4. Do I
achieve this by setting the skew parameter to 1.4?
- How can I limit the number range to a certain interval e.g. [1..65636] without
violating the randomness in the distribution?
Again, excuse me for my rather silly questions...
Michael
Martin Jansche wrote:

Devroye gives a rejection method for sampling from the Zipf
distribution here: http://cg.scs.carleton.ca/~luc/chapter_ten.pdf
-- mj
On Wed, May 28, 2008 at 4:25 PM, Michael Duerr <address@hidden> wrote:

Hi,
I'm looking for a function that can produce random numbers that are
Zipf-distributed?
Something like:
int zipfian(double skew, int N),
where skew is the skew factor (e.g. 0.4) and N the upper limit of the range
(e.g. [0, N) )
Does gsl hold something similar or can you provide me a reference for a
sample implementation?
Thanks,
Michael
_______________________________________________
Help-gsl mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gsl

**
**`plot.pdf`

*Description:* Adobe PDF document