35 lines
997 B
C++
35 lines
997 B
C++
/*
|
|
Copyright (c) 2014 IOnU Security Inc. All rights reserved
|
|
Created February 2014 by Kendrick Webster
|
|
|
|
Random.h - header for random number generator
|
|
*/
|
|
#pragma once
|
|
#include <stdint.h>
|
|
#include <string>
|
|
|
|
/*
|
|
Simple/fast 'random' number source based on an entropy pool seeded by high-resolution
|
|
timestamps. SeedRandom() should be called by I/O functions, event loops, etc.
|
|
*/
|
|
namespace ionu { namespace random {
|
|
|
|
// get <n> 'random' bytes from this module's RNG
|
|
void GetRandom(void* p, size_t n);
|
|
|
|
// fill <v> with random bytes
|
|
template<typename T>
|
|
void Random(T& v) {GetRandom(&v, sizeof(v));}
|
|
|
|
// adds entropy to pool by hashing a high-resolution timestamp
|
|
void SeedRandom(void);
|
|
|
|
// returns a hexadecimal string representing the last seed hashed by SeedRandom()
|
|
std::string GetLastSeedAsString(void);
|
|
|
|
// returns a random base64 string of length <n>,
|
|
// uses '_' and '-' as the two non-alnum chars (see b64char() in Hash.hpp)
|
|
std::string GetRandomString(size_t n);
|
|
|
|
}}
|