qswiki/random.h

30 lines
573 B
C

2018-11-03 17:12:20 +01:00
#ifndef RANDOM_H
#define RANDOM_H
#include <unistd.h>
#include <sys/syscall.h>
#ifdef __linux__
#include <sys/random.h>
2018-11-03 17:12:20 +01:00
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string>
#if __OpenBSD__
inline int getrandom(void *buf, size_t buflen, unsigned int flags)
{
arc4random_buf(buf, buflen);
return 0;
}
#endif
/* TODO: if the >=C++11 prngr are good enough, use them */
class Random
{
public:
Random();
2021-04-17 12:44:43 +02:00
std::string getRandomHexString(unsigned int bytes) const;
std::vector<char> getRandom(unsigned int bytes) const;
2018-11-03 17:12:20 +01:00
};
#endif // RANDOM_H