| 396 | } |
| 397 | |
| 398 | string PickRandomKey(random::SimplePhilox* rnd, |
| 399 | const std::vector<string>& keys) { |
| 400 | if (keys.empty()) { |
| 401 | return "foo"; |
| 402 | } else { |
| 403 | const int index = rnd->Uniform(keys.size()); |
| 404 | string result = keys[index]; |
| 405 | switch (rnd->Uniform(3)) { |
| 406 | case 0: |
| 407 | // Return an existing key |
| 408 | break; |
| 409 | case 1: { |
| 410 | // Attempt to return something smaller than an existing key |
| 411 | if (!result.empty() && result[result.size() - 1] > '\0') { |
| 412 | result[result.size() - 1]--; |
| 413 | } |
| 414 | break; |
| 415 | } |
| 416 | case 2: { |
| 417 | // Return something larger than an existing key |
| 418 | Increment(&result); |
| 419 | break; |
| 420 | } |
| 421 | } |
| 422 | return result; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | private: |
| 427 | Options options_; |