MCPcopy Create free account
hub / github.com/F-Stack/f-stack / powerLawRand

Function powerLawRand

app/redis-6.2.6/src/redis-cli.c:8102–8111  ·  view source on GitHub ↗

Return an integer from min to max (both inclusive) using a power-law * distribution, depending on the value of alpha: the greater the alpha * the more bias towards lower values. * * With alpha = 6.2 the output follows the 80-20 rule where 20% of * the returned numbers will account for 80% of the frequency. */

Source from the content-addressed store, hash-verified

8100 * With alpha = 6.2 the output follows the 80-20 rule where 20% of
8101 * the returned numbers will account for 80% of the frequency. */
8102long long powerLawRand(long long min, long long max, double alpha) {
8103 double pl, r;
8104
8105 max += 1;
8106 r = ((double)rand()) / RAND_MAX;
8107 pl = pow(
8108 ((pow(max,alpha+1) - pow(min,alpha+1))*r + pow(min,alpha+1)),
8109 (1.0/(alpha+1)));
8110 return (max-1-(long long)pl)+min;
8111}
8112
8113/* Generates a key name among a set of lru_test_sample_size keys, using
8114 * an 80-20 distribution. */

Callers 1

LRUTestGenKeyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected