2018-05-21 07:48:17 -06:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-05-21 07:48:17 -06:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
2021-01-13 06:54:19 -07:00
|
|
|
#include <memory>
|
2018-06-14 08:26:11 -06:00
|
|
|
#include <type_traits>
|
2018-05-21 07:48:17 -06:00
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
|
|
|
namespace Common::Random
|
|
|
|
{
|
|
|
|
/// Fill `buffer` with random bytes using a cryptographically secure pseudo-random number generator.
|
|
|
|
void Generate(void* buffer, std::size_t size);
|
2018-06-14 08:26:11 -06:00
|
|
|
|
|
|
|
/// Generates a random value of arithmetic type `T`
|
|
|
|
template <typename T>
|
|
|
|
T GenerateValue()
|
|
|
|
{
|
|
|
|
static_assert(std::is_arithmetic<T>(), "T must be an arithmetic type in GenerateValue.");
|
|
|
|
T value;
|
|
|
|
Generate(&value, sizeof(value));
|
|
|
|
return value;
|
|
|
|
}
|
2018-05-21 07:48:17 -06:00
|
|
|
} // namespace Common::Random
|