Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
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 be3// found in the LICENSE file. See the AUTHORS file for names of contributors.5#include "util/testutil.h"7#include "util/random.h"9namespace leveldb {10namespace test {12Slice RandomString(Random* rnd, int len, std::string* dst) {13dst->resize(len);14for (int i = 0; i < len; i++) {15(*dst)[i] = static_cast<char>(' ' + rnd->Uniform(95)); // ' ' .. '~'16}17return Slice(*dst);18}20std::string RandomKey(Random* rnd, int len) {21// Make sure to generate a wide variety of characters so we22// test the boundary conditions for short-key optimizations.23static const char kTestChars[] = {'\0', '\1', 'a', 'b', 'c',24'd', 'e', '\xfd', '\xfe', '\xff'};25std::string result;26for (int i = 0; i < len; i++) {27result += kTestChars[rnd->Uniform(sizeof(kTestChars))];28}29return result;30}32Slice CompressibleString(Random* rnd, double compressed_fraction, size_t len,33std::string* dst) {34int raw = static_cast<int>(len * compressed_fraction);35if (raw < 1) raw = 1;36std::string raw_data;37RandomString(rnd, raw, &raw_data);39// Duplicate the random data until we have filled "len" bytes40dst->clear();41while (dst->size() < len) {42dst->append(raw_data);43}44dst->resize(len);45return Slice(*dst);46}48} // namespace test49} // namespace leveldb
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.