xref: /aosp_15_r20/external/cronet/base/allocator/partition_allocator/src/partition_alloc/random.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PARTITION_ALLOC_RANDOM_H_
6 #define PARTITION_ALLOC_RANDOM_H_
7 
8 #include <cstdint>
9 
10 #include "partition_alloc/partition_alloc_base/component_export.h"
11 
12 namespace partition_alloc {
13 
14 namespace internal {
15 
16 // Returns a random value. The generator's internal state is initialized with
17 // `base::RandUint64` which is very unpredictable, but which is expensive due to
18 // the need to call into the kernel. Therefore this generator uses a fast,
19 // entirely user-space function after initialization.
20 PA_COMPONENT_EXPORT(PARTITION_ALLOC) uint32_t RandomValue();
21 
22 }  // namespace internal
23 
24 // Sets the seed for the random number generator to a known value, to cause the
25 // RNG to generate a predictable sequence of outputs. May be called multiple
26 // times.
27 PA_COMPONENT_EXPORT(PARTITION_ALLOC) void SetMmapSeedForTesting(uint64_t seed);
28 
29 }  // namespace partition_alloc
30 
31 #endif  // PARTITION_ALLOC_RANDOM_H_
32