--- nbase_rnd.c.orig	Mon Mar  3 15:21:50 2008
+++ nbase_rnd.c	Thu Apr 24 23:15:11 2008
@@ -103,6 +103,7 @@
 #include "nbase.h"
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 #if HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif
@@ -117,6 +118,7 @@
   FILE *fp = NULL;
   unsigned int i;
   short *iptr;
+  short step;
   
   if (numbytes < 0 || numbytes > 0xFFFF) return -1;
   
@@ -142,12 +144,14 @@
 	gettimeofday(&tv, NULL);
 	srand((tv.tv_sec ^ tv.tv_usec) ^ getpid());
       }
-      
-      for(i=0; i < sizeof(bytebuf) / sizeof(short); i++) {
-	iptr = (short *) ((char *)bytebuf + i * sizeof(short));
+      if (RAND_MAX >= 0xFFFF) {
+        step = sizeof(short);
+      } else step = 1;
+      for(i=0; i < sizeof(bytebuf) / step; i++) {
+	iptr = (short *) ((char *)bytebuf + i * step);
 	*iptr = rand();
       }
-      bytesleft = (sizeof(bytebuf) / sizeof(short)) * sizeof(short);
+      bytesleft = (sizeof(bytebuf) / step) * step;
       /*    ^^^^^^^^^^^^^^^not as meaningless as it looks  */
     } else fclose(fp);
   }
