* Random number generator: uniform distribution from min to max inclusive. * * Although the limits are expressed as int64, you can't generate the full * int64 range in one call, because the difference of the limits mustn't * overflow int64. In practice it's unwise to ask for more than an int32 * range, because of the limited precision of pg_erand48(). */
| 929 | * range, because of the limited precision of pg_erand48(). |
| 930 | */ |
| 931 | static int64 |
| 932 | getrand(RandomState *random_state, int64 min, int64 max) |
| 933 | { |
| 934 | /* |
| 935 | * Odd coding is so that min and max have approximately the same chance of |
| 936 | * being selected as do numbers between them. |
| 937 | * |
| 938 | * pg_erand48() is thread-safe and concurrent, which is why we use it |
| 939 | * rather than random(), which in glibc is non-reentrant, and therefore |
| 940 | * protected by a mutex, and therefore a bottleneck on machines with many |
| 941 | * CPUs. |
| 942 | */ |
| 943 | return min + (int64) ((max - min + 1) * pg_erand48(random_state->xseed)); |
| 944 | } |
| 945 | |
| 946 | /* |
| 947 | * random number generator: exponential distribution from min to max inclusive. |
no test coverage detected