aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez>2005-03-29 14:17:28 +0000
committerantirez <antirez>2005-03-29 14:17:28 +0000
commitb0e3d498bf73bfebe7d1fe92e39518fe8c66e936 (patch)
treeb0ccc954d32a5f9f1b1c881937b3ed378d1392ba
parent21cc2d45e2a0220ac11e8cf6a6519d7edeafd357 (diff)
downloadjimtcl-b0e3d498bf73bfebe7d1fe92e39518fe8c66e936.zip
jimtcl-b0e3d498bf73bfebe7d1fe92e39518fe8c66e936.tar.gz
jimtcl-b0e3d498bf73bfebe7d1fe92e39518fe8c66e936.tar.bz2
Fixed [range] for the case of unique element possible as output.
-rw-r--r--ChangeLog6
-rw-r--r--jim.c8
2 files changed, 10 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index ca79202..9d60cec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-03-29 16:03 antirez
+
+ * ChangeLog, jim.c: random number generator fixed. Was a problem
+ with the initialization of the sbox. (see prev CVS commit
+ comment.)
+
2005-03-29 15:43 antirez
* ChangeLog, jim.c: First fix for [rand]. More later as there is an
diff --git a/jim.c b/jim.c
index 1015164..8348bfd 100644
--- a/jim.c
+++ b/jim.c
@@ -2,7 +2,7 @@
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
* Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
*
- * $Id: jim.c,v 1.135 2005/03/29 14:03:44 antirez Exp $
+ * $Id: jim.c,v 1.136 2005/03/29 14:17:28 antirez Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -10892,13 +10892,13 @@ static int Jim_RandCoreCommand(Jim_Interp *interp, int argc,
Jim_SetResultString(interp, "Invalid arguments (max < min)", -1);
return JIM_ERR;
}
- maxMul = JIM_WIDE_MAX - (JIM_WIDE_MAX%len);
+ maxMul = JIM_WIDE_MAX - (len ? (JIM_WIDE_MAX%len) : 0);
while (1) {
jim_wide r;
JimRandomBytes(interp, &r, sizeof(jim_wide));
if (r < 0 || r >= maxMul) continue;
- r = r%len;
+ r = (len == 0) ? 0 : r%len;
Jim_SetResult(interp, Jim_NewIntObj(interp, min+r));
return JIM_OK;
}
@@ -11035,7 +11035,7 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
printf("Welcome to Jim version %d.%d, "
"Copyright (c) 2005 Salvatore Sanfilippo\n",
JIM_VERSION / 100, JIM_VERSION % 100);
- printf("CVS ID: $Id: jim.c,v 1.135 2005/03/29 14:03:44 antirez Exp $\n");
+ printf("CVS ID: $Id: jim.c,v 1.136 2005/03/29 14:17:28 antirez Exp $\n");
Jim_SetVariableStrWithStr(interp, "jim_interactive", "1");
while (1) {
char buf[1024];