| 998 | } |
| 999 | |
| 1000 | RAND_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 | |
| 1028 | double random_triangular(bitgen_t *bitgen_state, double left, double mode, |
| 1029 | double right) { |
no test coverage detected