<div>
<div>
<span>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">The question is: how to return the same sequence of numbers</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">using random system. The idea was not to build new one but</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">find a way in which - if need it - personal 'seed-state' can</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">be saved and used.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">The solution I found is simple, and with out compromising</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">the random system with other alternatives - I think.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">If any of you found/have other solution to the problem</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">and like to share the code, please let me know.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">best wishes,</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">Janusz</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">(defun save-random-state (file &optional (state *random-state*)) </p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (with-open-file (o file :direction :output</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> :if-does-not-exist :create</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> :if-exists :supersede)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (with-standard-io-syntax</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (format o "~&;;; dumped ~D~%~S~%" (get-universal-time) state)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (values state file))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">(defun load-random-state (file)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (if (probe-file file)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (with-open-file (i file :direction :input)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (with-standard-io-syntax</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (values (read i) file))) nil))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">;(save-random-state "~/lisp/seed-state")</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">;(load-random-state "~/lisp/seed-state")</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">;if 'seed-state' file is not found 'default' random-state is used.</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">(defun seed-state (n)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> ;(seed-state 0.34) => 0.7094518</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> ;(seed-state 0.33) => 0.15447316</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (prog (st seed-state result)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq st (load-random-state "~/lisp/seed-state"))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq seed-state</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (if (null st)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (ccl::initialize-mrg31k3p-state 568510646 776752825 1566514914 1437072568 929117308 264016807) ;default, can be changed</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> st))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq n (if (integerp n) n (round (* n 100))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (dotimes (i n)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq result (random 1.0 seed-state)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (return result)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">(defun rnd (&optional seed)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> ;(rnd) => ?</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> ;(rnd 0.31) => 0.35242736</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (if (null seed) (random 1.0) (seed-state seed)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica">(defun rndm (n &optional seed)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> ;(rndm 6) => ?</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> ;(rndm 5 0.23) => (0.80377346 0.5047488 0.1521786 0.5202181 0.7054099)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> ;(rndm 5 0.24) => (0.5047488 0.1521786 0.5202181 0.7054099 0.08438743)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (prog (out result)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq seed (if (null seed) seed</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (1- (if (integerp seed) seed (round (* seed 100))))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (cond ((null seed)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (dotimes (i n)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq out (random 1.0))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq result (cons out result))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (t (dotimes (i n)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq out (seed-state (incf seed)))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (setq result (cons out result)))))</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica"> (return (nreverse result))))</p><p></p>
</span>
<span><br>--<div>MRAC Publishing</div><div>Janusz Podrazik</div><br></span>
</div>
</div>