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

Function random_geometric_search

numpy/random/src/distributions/distributions.c:963–978  ·  view source on GitHub ↗

Still used but both generator and mtrand via legacy_random_geometric */

Source from the content-addressed store, hash-verified

961
962/* Still used but both generator and mtrand via legacy_random_geometric */
963RAND_INT_TYPE random_geometric_search(bitgen_t *bitgen_state, double p) {
964 double U;
965 RAND_INT_TYPE X;
966 double sum, prod, q;
967
968 X = 1;
969 sum = prod = p;
970 q = 1.0 - p;
971 U = next_double(bitgen_state);
972 while (U > sum) {
973 prod *= q;
974 sum += prod;
975 X++;
976 }
977 return X;
978}
979
980int64_t random_geometric_inversion(bitgen_t *bitgen_state, double p) {
981 double z = ceil(-random_standard_exponential(bitgen_state) / npy_log1p(-p));

Callers 2

legacy_random_geometricFunction · 0.85
random_geometricFunction · 0.85

Calls 1

next_doubleFunction · 0.85

Tested by

no test coverage detected