Boost 1.55 버전 기준으로 작성했습니다.


#pragma once


//================================================================

/**

@author    skhong

@since     7/7/2014   17:16

@remarks   주사위를 굴리자

  

*/

//================================================================


#include <boost/random/mersenne_twister.hpp>

#include <boost/random/uniform_int_distribution.hpp>

#include <boost/random/uniform_real_distribution.hpp>

#include <boost/random/discrete_distribution.hpp>



#include "Singleton.h"


// 주사위 굴리기

struct RollDie

{

inline

int operator()( int _LowerBound = 0, int nUpperBound = 32767 )

{

static boost::mt19937 gen;

static BOOL init = FALSE;

if( !init )

{

gen.seed(std::time(0));

init = TRUE;

}

boost::random::uniform_int_distribution<> dist( _LowerBound, nUpperBound );

return dist(gen);

}

};


// 주사위 굴리기

struct fRollDie

{

inline

double operator()( double _LowerBound = 0.f, double nUpperBound = 32767.f )

{

static boost::mt19937 gen;

static BOOL init = FALSE;

if( !init )

{

gen.seed(std::time(0));

init = TRUE;

}


boost::random::uniform_real_distribution<> dist( _LowerBound, nUpperBound );

return dist(gen);

}

};


//

// 가중치를 가지는 주사위 굴리기

// 가중치는 1.0f

// 넘오는 가중치는 합이 1.0f을 넘지 않도록 한다.

struct RollWeightedDie

{

inline

int operator()( std::vector<double> const& _Probabilities )

{

static boost::mt19937 gen;

static BOOL init = FALSE;

if( !init )

{

gen.seed(std::time(0));

init = TRUE;

}


boost::random::discrete_distribution<> dist( _Probabilities );

return dist(gen);

}

};

'Boost' 카테고리의 다른 글

Boost Regex 실전 사용 샘플  (0) 2016.01.31
Boost Regex(정규식) 샘플  (0) 2016.01.31
Boost Pool 샘플  (0) 2016.01.31
Boost Optional 샘플  (0) 2016.01.31
Multi Index 샘플  (0) 2016.01.31
      Boost  |  2016. 1. 31. 23:30



홍쿤사마's Blog is powered by Daum