[ create a new paste ] login | about

Link: http://codepad.org/1W67PuRW    [ raw code | fork ]

C++, pasted on Jul 20:
//lb_random.h
#ifndef LB_RANDOM_H
#define LB_RANDOM_H

#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_01.hpp>

#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif

extern boost::uniform_01<boost::mt19937> prng;

extern "C" {
EXPORT double RandomDouble();
EXPORT void SeedWithTime();
EXPORT void Seed(unsigned value);
}

#endif

//---------------------------
//lb_random.cpp

#include <ctime>
#include "lb_random.h"

boost::uniform_01<boost::mt19937> prng((boost::mt19937()));
extern "C" {
EXPORT double RandomDouble()
{
    return prng();
}
}

namespace detail {
void reset(unsigned value)
{
    boost::mt19937 new_generator(value);
    prng = boost::uniform_01<boost::mt19937>(new_generator);
}
}
extern "C" {
EXPORT void SeedWithTime()
{
    detail::reset(std::time(0));
}

EXPORT void Seed(unsigned value)
{
    detail::reset(value);
}
}

//to compile (depending on your installation folder of boost): 
//g++ -I"C:/boost_1_38_0" -c -DBUILD_DLL lb_random.cpp -o lb_random.o

//to create dll:
//g++ -shared -o lb_random.dll lb_random.o -W1,--out-implib,libmessage.a -s


Create a new paste based on this one


Comments: