MCPcopy Create free account
hub / github.com/numpy/numpy / random_zipf

Function random_zipf

numpy/random/src/distributions/distributions.c:1000–1026  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

998}
999
1000RAND_INT_TYPE random_zipf(bitgen_t *bitgen_state, double a) {
1001 double am1, b;
1002
1003 am1 = a - 1.0;
1004 b = pow(2.0, am1);
1005 while (1) {
1006 double T, U, V, X;
1007
1008 U = 1.0 - next_double(bitgen_state);
1009 V = next_double(bitgen_state);
1010 X = floor(pow(U, -1.0 / am1));
1011 /*
1012 * The real result may be above what can be represented in a signed
1013 * long. Since this is a straightforward rejection algorithm, we can
1014 * just reject this value. This function then models a Zipf
1015 * distribution truncated to sys.maxint.
1016 */
1017 if (X > (double)RAND_INT_MAX || X < 1.0) {
1018 continue;
1019 }
1020
1021 T = pow(1.0 + 1.0 / X, am1);
1022 if (V * X * (T - 1.0) / (b - 1.0) <= T / b) {
1023 return (RAND_INT_TYPE)X;
1024 }
1025 }
1026}
1027
1028double random_triangular(bitgen_t *bitgen_state, double left, double mode,
1029 double right) {

Callers 1

legacy_random_zipfFunction · 0.85

Calls 3

powFunction · 0.85
next_doubleFunction · 0.85
floorFunction · 0.85

Tested by

no test coverage detected