mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 13:57:57 -07:00
2c2fb869a2
decreases runtime significantly and lessens dependency on mbedtls
27 lines
654 B
C++
27 lines
654 B
C++
// Copyright 2018 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <memory>
|
|
#include <type_traits>
|
|
|
|
#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);
|
|
|
|
/// 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;
|
|
}
|
|
} // namespace Common::Random
|