Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: RANDOMSMALL <range> [ <seed> ]



Peter Stephenson wrote:
> Look at the math function rand48 in the zsh/mathfunc package.

Ooops, this turns out to be badly broken when used with a seed
parameter.  After the second time you always get the same number.
Not actually all that random.

Index: Src/Modules/mathfunc.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/mathfunc.c,v
retrieving revision 1.4
diff -u -r1.4 mathfunc.c
--- Src/Modules/mathfunc.c	2 Jun 2004 22:15:00 -0000	1.4
+++ Src/Modules/mathfunc.c	8 Jun 2004 21:42:14 -0000
@@ -500,7 +500,7 @@
 		     * to each unsigned short.
 		     */
 		    for (i = 0; i < 3 && !do_init; i++) {
-			unsigned short *seedptr = seedbuf + i;
+			unsigned short *seedptr = seedbufptr + i;
 			*seedptr = 0;
 			for (j = 0; j < 4; j++) {
 			    if (*seedstr >= '0' && *seedstr <= '9')

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx>
Work: pws@xxxxxxx
Web: http://www.pwstephenson.fsnet.co.uk



Messages sorted by: Reverse Date, Date, Thread, Author