Skip to content
Snippets Groups Projects
random.hpp 807 B
Newer Older
  • Learn to ignore specific revisions
  • /*
     * random.hpp
     *
     * Created on: May 28, 2015
     * Author: Jan Travnicek
     */
    
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    #ifndef __RANDOM_HPP_
    #define __RANDOM_HPP_
    
    #include <random>
    #include <limits>
    
    
    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() ;
    		}
    
    
    		void seed ( unsigned int seed ) {
    			gen.seed ( seed );
    		}
    
    	};
    public:
    	static semirandom_device semirandom;
    
    };
    
    } /* namespace std */
    
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    #endif /* _RANDOM_HPP_ */