41 lines
588 B
C++
41 lines
588 B
C++
//
|
|
// Created by erki on 29.04.21.
|
|
//
|
|
|
|
#ifndef SKULLC_UTILITY_RAND_HPP
|
|
#define SKULLC_UTILITY_RAND_HPP
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Peripherals
|
|
{
|
|
|
|
inline std::uint32_t rand32(std::uint32_t& state)
|
|
{
|
|
std::uint32_t x = state;
|
|
x ^= x << 13;
|
|
x ^= x >> 17;
|
|
x ^= x << 5;
|
|
state = x;
|
|
|
|
return state;
|
|
}
|
|
|
|
inline std::uint64_t rand64(std::uint64_t& state)
|
|
{
|
|
std::uint64_t x = state;
|
|
x ^= x << 13;
|
|
x ^= x >> 7;
|
|
x ^= x << 17;
|
|
state = x;
|
|
|
|
return state;
|
|
}
|
|
|
|
void srand(const std::uint32_t& seed);
|
|
std::uint32_t rand();
|
|
|
|
}// namespace Peripherals
|
|
|
|
#endif//SKULLC_UTILITY_RAND_HPP
|