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

Function random_logseries

numpy/random/src/distributions/distributions.c:927–953  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

925}
926
927int64_t random_logseries(bitgen_t *bitgen_state, double p) {
928 double q, r, U, V;
929 int64_t result;
930
931 r = npy_log1p(-p);
932
933 while (1) {
934 V = next_double(bitgen_state);
935 if (V >= p) {
936 return 1;
937 }
938 U = next_double(bitgen_state);
939 q = -expm1(r * U);
940 if (V <= q * q) {
941 result = (int64_t)floor(1 + log(V) / log(q));
942 if ((result < 1) || (V == 0.0)) {
943 continue;
944 } else {
945 return result;
946 }
947 }
948 if (V >= q) {
949 return 1;
950 }
951 return 2;
952 }
953}
954
955/*
956 * RAND_INT_TYPE is used to share integer generators with RandomState which

Callers

nothing calls this directly

Calls 5

npy_log1pFunction · 0.85
next_doubleFunction · 0.85
expm1Function · 0.85
floorFunction · 0.85
logFunction · 0.50

Tested by

no test coverage detected