40 lines
819 B
C++
40 lines
819 B
C++
/*
|
|
Copyright (c) 2014 IOnU Security Inc. All rights reserved
|
|
Created February 2014 by Kendrick Webster
|
|
|
|
Random.cpp - implementation for Random.h
|
|
*/
|
|
#include "Hash.hpp"
|
|
#include "Random.h"
|
|
#include <stdio.h>
|
|
#include <chrono>
|
|
|
|
namespace
|
|
{
|
|
ionu::hash::CHash rng_hash;
|
|
std::chrono::steady_clock::time_point rng_seed;
|
|
}
|
|
|
|
void ionu::random::GetRandom(void* p, size_t n)
|
|
{
|
|
rng_hash.GetAndMix(p, n);
|
|
}
|
|
|
|
void ionu::random::SeedRandom(void)
|
|
{
|
|
rng_seed = std::chrono::steady_clock::now();
|
|
rng_hash.Hash(&rng_seed, sizeof(rng_seed));
|
|
}
|
|
|
|
std::string ionu::random::GetLastSeedAsString(void)
|
|
{
|
|
char s[17];
|
|
snprintf(s, sizeof(s), "%.16lX", *reinterpret_cast<uint64_t*>(&rng_seed));
|
|
return s;
|
|
}
|
|
|
|
std::string ionu::random::GetRandomString(size_t n)
|
|
{
|
|
return rng_hash.GetStringAndMix(n);
|
|
}
|