make_random_state broken for Maxima installed with Ecl



Oliver Kullmann wrote:
> I have now the problem that I use make_random_state(0)
> at quite a few places.
> 
> So it seems I need to assemble my own Maxima package:
>  - the module "maxima" of the cvs repository is to be used?
>  - once I see on "Index of /maxima/src" 
> http://maxima.cvs.sourceforge.net/maxima/maxima/src/?sortby=date#dirlist
>    that the changes I'm looking for appeared, I have to
>    download the module "maxima", go into the 5.16.3 package
>    and replace all related entries there with the downloaded
>    ones?

This is Lisp.  You don't have to do that.  For a quick fix, put the code 
below into a file, say, rand-fix.lisp.  Then, in maxima, do

:lisp (load "<path>/rand-fix.lisp")

Then you'll have the fixed version.  You may want to compile the file to 
make it run a little faster, like so:

:lisp (load (compile-file "<path>/rand-fix.lisp"))

You can put similar commands into maxima-init if you like.

Ray


(in-package :mt19937)
(defun int-init-random-state (&optional (seed 5489) state)
   (declare (type (integer 0 #xffffffff) seed))
   (let ((state (or state (make-array 627 :element-type '(unsigned-byte 
32)))))
     (declare (type (simple-array (unsigned-byte 32) (627)) state))
     (setf (aref state 0) 0)
     (setf (aref state 1) #x9908b0df)
     (setf (aref state 2) mt19937-n)
     (setf (aref state 3) seed)
     (do ((k 1 (1+ k)))
	((>= k 624))
       (declare (type (mod 625) k))
       (let ((prev (aref state (+ 3 (1- k)))))
	(setf (aref state (+ 3 k))
	      (logand (+ (* 1812433253 (logxor prev (ash prev -30)))
			 k)
		      #xffffffff))))
     state))