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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors