Random.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#include "squid.h"
10#include "base/Random.h"
11
12std::mt19937::result_type
14{
15 // We promise entropy collection without waiting, but there is no standard
16 // way to get that in all environments. We considered these device names:
17 //
18 // * none: The default constructor in some specialized STL implementation or
19 // build might select a device that requires Squid to wait for entropy.
20 //
21 // * "default": Leads to clang (and other STLs) exceptions in some builds
22 // (e.g., when clang is built to use getentropy(3) or rand_s()).
23 //
24 // * "/dev/urandom": Blocks GCC from picking the best entropy source (e.g.,
25 // arc4random(3)) and leads to GCC/clang exceptions in some environments.
26 //
27 // If a special supported environment needs a non-default device name, we
28 // will add a random_device_name configuration directive. We cannot detect
29 // such needs in general code and choose to write simpler code until then.
30 static std::random_device dev;
31 return dev();
32}
33
34std::mt19937_64::result_type
36{
37 std::mt19937_64::result_type left = RandomSeed32();
38 return (left << 32) | RandomSeed32();
39}
40
std::mt19937::result_type RandomSeed32()
Definition: Random.cc:13
std::mt19937_64::result_type RandomSeed64()
a 64-bit version of RandomSeed32()
Definition: Random.cc:35

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors