
Hi there,
Thank you in advance for many people suggesting solution for this problem!
On 2014/11/01 20:59, Travis Cardwell
If it works with the algorithm, you could use a pseudo-random number generator with a fixed seed. For example, here is a program to estimate
the value of π (purely) using a Monte Carlo simulation:
I got it. But, in my case, fixing initial seed might cause inefficiency, so I can't take this way in this case.
By the way, this approach seems works well for other cases which is not so quality sensitive.
On 2014/11/02 1:02, Carter Schonwald
Hrm, you could make a num instance of a newtype wrapped state monad thats threading around your math!
newtype MyNum = MN (State StdGen TheNumberType)
This is almost the same as what I mean by "CPS-ing". We can omit generator argument by this approach,
but we have to pass generator whenever we want to get the result or inspect the intermediate value.
On 2014/11/02 1:15, Jun Inoue
Just an idea here, but would implicit-params work? It only gives you Reader-monad capabilities, but you can always split random generators. There might be repercussions for the quality of the generated numbers, though, for which I have no idea.
I think this is virtually the same as Travis's approach, because it returns same seed whenever we split the global value. And, yes, this causes repercussions for the random quality, and not suitable for my case. Perhaps we can parametrize `IORef StdGen` instead of `StdGen` so that we can change the state, but we have to call `unsafePerformIO` internally whenever accessing random generator, and then this appoarch became almost the same as my initial approach. By the way, we can control initial value with this implicit parameter approach, this might improve the random quality slightly than splitting global generator beforewards. -- Hiromi ISHII konn.jinro@gmail.com