random.h 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2019 The Chromium 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.
  4. #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_RANDOM_H_
  5. #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_RANDOM_H_
  6. #include <stdint.h>
  7. #include "base/allocator/partition_allocator/partition_alloc_base/component_export.h"
  8. namespace partition_alloc {
  9. namespace internal {
  10. // Returns a random value. The generator's internal state is initialized with
  11. // `base::RandUint64` which is very unpredictable, but which is expensive due to
  12. // the need to call into the kernel. Therefore this generator uses a fast,
  13. // entirely user-space function after initialization.
  14. PA_COMPONENT_EXPORT(PARTITION_ALLOC) uint32_t RandomValue();
  15. } // namespace internal
  16. // Sets the seed for the random number generator to a known value, to cause the
  17. // RNG to generate a predictable sequence of outputs. May be called multiple
  18. // times.
  19. PA_COMPONENT_EXPORT(PARTITION_ALLOC) void SetMmapSeedForTesting(uint64_t seed);
  20. } // namespace partition_alloc
  21. #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_RANDOM_H_