<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Dear Chide,<br>
<br>
Clean has a library for generating pseudo random numbers:
MersenneTwister. As explained in the dcl file this produces pretty
good random numbers based on an algorithm described in "Mersenne
Twister: A 623-dimensionally equidistributed uniform pseudorandom
number generator" by M. Matsumoto and T. Nishimura in ACM
Transactions on Modeling and Computer Simulation, vol. 8, no. 1,
January 1998, pp. 3-30.<br>
<br>
A simple way to distribute random numbers is the 'plumbing' approach
of Burton and Page. If there is some state (like world or for IO)
passed around you insert the list of numbers in the state and take
as many values as you need. From your description I have the
impression that this does not solve your problem. It is possible to
introduce such a state, but that can have a huge (and unwanted)
impact on the structure of your program. It depends on your program
if the plumbing approach will work well.<br>
<br>
Spliting random stream in oven and odd values has a severe space
leak penalty as Burton and Page point out. I used a scheme were
random streams are split by starting a new stream with the current
random number as seed:<br>
<br>
split :: [Int] -> ([Int],[Int])<br>
split [a:x] = (genRandInt a, x)<br>
<br>
This is somewhat similar to the random splitting of sequences as
proposed by Burton and Page. For the Mersenne Twister the next
random number is generally not related to a new sequence using the
current number as seed.<br>
For a program that uses a huge number of splits this can have a
space penalty: each generator uses an array and all those arrays
together can consume a significant amount of memory (depending on
the number of splits and if they can be removed by the garbage
collector or not). <br>
<br>
If you do not want to have a state in your program for plumbing
random numbers and need a huge number of splits, you can consider to
use a simpler algorithm to generate pseudo random numbers. More
specific: an algorithm that does not use much memory. For instance
the algorithm used in Haskell as outlined in the Burton and Page
paper.<br>
<br>
So, unfortunately the final answer is 'it depends'. I am not aware
of a library solving the problem for you.<br>
<br>
Hope this helps,<br>
<br>
Pieter<br>
<br>
On 09/11/2011 11:22 PM, Groenouwe, C. wrote:
<blockquote
cite="mid:8F6DD0D591ECE64B859B081E73E2BEEF0C3CA211@PEXMB002B.vu.local"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
<div style="direction: ltr;font-family: Tahoma;color:
#000000;font-size: 10pt;">Dear Pieter (and others Clean
specialists),<br>
<br>
I tried to use random numbers in my clean program, however, I
ran into the problem of distributing the pseudo random sequence
to the different parts of my program. What is an elegant
solution which doesn't restrict your program so much that it
breaks possibilities for parallel computing etc. etc.? Doing
some research I found this article:<br>
<br>
<a moz-do-not-send="true"
href="http://mailman.science.ru.nl/pipermail/clean-list/"
target="_blank"><cite>http://www.cs.ou.edu/~rlpage/<b>Burton</b>PageRngJFP.pdf</cite></a><br>
<br>
and an old thread on the clean-list mailing list about this
topic:<br>
<br>
<a class="moz-txt-link-freetext" href="http://mailman.science.ru.nl/pipermail/clean-list/1995/000022.html">http://mailman.science.ru.nl/pipermail/clean-list/1995/000022.html</a><br>
<br>
which also turned out to refer to the mentioned article. My
question is: which of the proposed methods in the thread and
article do you recommend? Are there also libraries available to
support the distribution?
<br>
<br>
Additional info: my program doesn't do much I/O, so I don't know
whether "piggy backing" on the World parameter is an elegant
solution (a suggestion I read in the old thread). Is the method
of choice of Burton and Page also the best according to you
(random splitting of a random sequence)?<br>
<br>
TIA!<br>
<br>
Chide<br>
</div>
</blockquote>
</body>
</html>