| 925 | } |
| 926 | |
| 927 | int64_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 |
nothing calls this directly
no test coverage detected