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. */
| 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. */ |
| 8102 | long 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. */ |