Boost logo

Boost :

Subject: Re: [boost] [Random] reproducing numbers generated by R.
From: Ronan Trépos (Ronan.Trepos_at_[hidden])
Date: 2010-08-06 11:10:41


Le 05/08/2010 22:32, Steven Watanabe a écrit :
> AMDG
>
> Ronan Trépos wrote:
>> For validity concerns, I'm trying to reproduce pseudo random numbers
>> generated by the sofware R with boost::random library.
>> The R default number generator is the Mersenne-Twister with period
>> 2^19937 -1 .
>>
>> 1. In R I tried :
>>
>> > set.seed(13)
>> > runif(1)
>>
>> 0.7103224
>>
>> 2. With boost I tried :
>>
>> boost::mt19937 rng(13);
>> boost::uniform_01<boost::mt19937> zeroone(rng);
>> std::cout << zeroone() << std::endl;
>>
>> 0.777702
>>
>> Has someone already experienced that ? Is it possible to reproduce
>> the same numbers ?
>> Maybe the mismatch comes from the fact that generated integers are
>> translated into [0;1)..
>
> I don't think so. I think the difference is that R uses its own
> seeding algorithm.

Ok, thank you. I think I will give up.

In R, concerning the MT generator, it is said :
"The ‘seed’ is a 624-dimensional set of 32-bit integers plus a current
position in that set."
I understand that the 'seed' is actually the MT state.
Calling set.seed in R creates the .Random.seed object which is a
626-dimensional set.
(however I did not find what is the seeding algorithm used in set.seed).
I think that the 624 last integers are the MT state and that the 2nd
integer should be the current position in that set.

In boost, I tried to construct the MT directly with the
mersenne-twister(It& first, It last) constructor where It is
an iterator on an integer vector containing .Random.seed values. I
presume this constructor can be used to directly inititialise the MT
state. Am I right ?

However, this process did not work neither.

Best regards,
Ronan Trépos

> In Christ,
> Steven Watanabe
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost

-- 
Trépos Ronan
INRA unité BIA, équipe MAD, Toulouse
http://carlit.toulouse.inra.fr/wikiz/index.php/Ronan_TREPOS
tel : 05 61 28 53 34

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk