2015-10-22 17:36:03 +02:00
|
|
|
#ifndef MESSMER_CPPUTILS_RANDOM_RANDOMGENERATOR_H
|
|
|
|
#define MESSMER_CPPUTILS_RANDOM_RANDOMGENERATOR_H
|
|
|
|
|
|
|
|
#include "../data/FixedSizeData.h"
|
|
|
|
#include "../data/Data.h"
|
|
|
|
|
|
|
|
namespace cpputils {
|
|
|
|
class RandomGenerator {
|
|
|
|
public:
|
|
|
|
template<size_t SIZE> FixedSizeData<SIZE> getFixedSize();
|
|
|
|
Data get(size_t size);
|
|
|
|
|
|
|
|
protected:
|
2015-10-23 20:21:17 +02:00
|
|
|
virtual void _get(void *target, size_t bytes) = 0;
|
2015-10-22 17:36:03 +02:00
|
|
|
private:
|
|
|
|
static std::mutex _mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<size_t SIZE> inline FixedSizeData<SIZE> RandomGenerator::getFixedSize() {
|
|
|
|
FixedSizeData<SIZE> result = FixedSizeData<SIZE>::Null();
|
2015-10-23 20:21:17 +02:00
|
|
|
_get(result.data(), SIZE);
|
2015-10-22 17:36:03 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Data RandomGenerator::get(size_t size) {
|
|
|
|
Data result(size);
|
2015-10-23 20:21:17 +02:00
|
|
|
_get(result.data(), size);
|
2015-10-22 17:36:03 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|