1
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file. See the AUTHORS file for names of contributors.
5
#include "util/testutil.h"
7
#include "util/random.h"
12
Slice RandomString(Random* rnd, int len, std::string* dst) {
14
for (int i = 0; i < len; i++) {
15
(*dst)[i] = static_cast<char>(' ' + rnd->Uniform(95)); // ' ' .. '~'
20
std::string RandomKey(Random* rnd, int len) {
21
// Make sure to generate a wide variety of characters so we
22
// test the boundary conditions for short-key optimizations.
23
static const char kTestChars[] = {
24
'\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff'
27
for (int i = 0; i < len; i++) {
28
result += kTestChars[rnd->Uniform(sizeof(kTestChars))];
34
extern Slice CompressibleString(Random* rnd, double compressed_fraction,
35
int len, std::string* dst) {
36
int raw = static_cast<int>(len * compressed_fraction);
39
RandomString(rnd, raw, &raw_data);
41
// Duplicate the random data until we have filled "len" bytes
43
while (dst->size() < len) {
44
dst->append(raw_data);
51
} // namespace leveldb