Skip to content
Snippets Groups Projects
Commit 1fe35ac4 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

statically available random and semirandom devices

parent 149f5cd8
No related branches found
No related tags found
No related merge requests found
/*
* istream.cpp
*
* Created on: Apr 1, 2013
* Author: Jan Travnicek
*/
#include "../random"
namespace std {
random_device random_devices::random;
random_devices::semirandom_device random_devices::semirandom;
}
/*
* random.hpp
*
* Created on: May 28, 2015
* Author: Jan Travnicek
*/
#ifndef RANDOM_HPP_
#define RANDOM_HPP_
namespace std {
class random_devices {
public:
static random_device random;
private:
class semirandom_device {
public:
typedef unsigned int result_type;
private:
std::mt19937 gen;
std::uniform_int_distribution<unsigned int> dis;
public:
semirandom_device() : gen(random_devices::random()) {
}
result_type operator()() {
return dis(gen);
}
result_type min() {
return 0;
}
result_type max() {
return numeric_limits<result_type>::max() ;
}
};
public:
static semirandom_device semirandom;
};
} /* namespace std */
#endif /* ALGORITHM_HPP_ */
#ifndef __RANDOM_HEADER_WRAPPER_
#define __RANDOM_HEADER_WRAPPER_
#include <bits/../random>
#include "limits"
#include "extensions/random.hpp"
#endif /* __RANDOM_HEADER_WRAPPER_ */
#include "RandomTest.h"
#include <random>
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RandomTest, "bits" );
CPPUNIT_TEST_SUITE_REGISTRATION( RandomTest );
void RandomTest::setUp() {
}
void RandomTest::tearDown() {
}
void RandomTest::testRandom() {
std::cout << std::random_devices::random() << std::endl;
std::cout << std::random_devices::semirandom() << std::endl;
}
#ifndef RANDOM_TEST_H_
#define RANDOM_TEST_H_
#include <cppunit/extensions/HelperMacros.h>
class RandomTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( RandomTest );
CPPUNIT_TEST( testRandom );
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void testRandom();
};
#endif // RANDOM_TEST_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment