diff options
author | Jay Belanger <jay.p.belanger@gmail.com> | 2007-07-06 02:06:30 +0000 |
---|---|---|
committer | Jay Belanger <jay.p.belanger@gmail.com> | 2007-07-06 02:06:30 +0000 |
commit | e4ebbf4941152518b7eaa8d53dcd5ecf7a5a5e8c (patch) | |
tree | cef19f2ee9527f16c6368cb8ac9f2f00f4cdeac8 /lisp/calc/calc-comb.el | |
parent | 33f400c3152114b1e4368425e0c57e2ae213558c (diff) | |
download | emacs-e4ebbf4941152518b7eaa8d53dcd5ecf7a5a5e8c.tar.gz |
(math-random-digit): Rename to `math-random-three-digit-number'.
(math-random-digits): Don't depend on representation of integers.
Diffstat (limited to 'lisp/calc/calc-comb.el')
-rw-r--r-- | lisp/calc/calc-comb.el | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lisp/calc/calc-comb.el b/lisp/calc/calc-comb.el index 7bda9972426..ede04fd5032 100644 --- a/lisp/calc/calc-comb.el +++ b/lisp/calc/calc-comb.el @@ -615,7 +615,8 @@ ;;; Avoid various pitfalls that may lurk in the built-in (random) function! ;;; Shuffling algorithm from Numerical Recipes, section 7.1. (defvar math-random-last) -(defun math-random-digit () +(defun math-random-three-digit-number () + "Return a random three digit number." (let (i) (or (and (boundp 'var-RandSeed) (eq var-RandSeed math-last-RandSeed)) (math-init-random-base)) @@ -635,17 +636,17 @@ ;;; Produce an N-digit random integer. (defun math-random-digits (n) - (cond ((<= n 6) - (math-scale-right (+ (* (math-random-digit) 1000) (math-random-digit)) - (- 6 n))) - (t (let* ((slop (% (- 900003 n) 3)) - (i (/ (+ n slop) 3)) - (digs nil)) - (while (> i 0) - (setq digs (cons (math-random-digit) digs) - i (1- i))) - (math-normalize (math-scale-right (cons 'bigpos digs) - slop)))))) + "Produce a random N digit integer." + (let* ((slop (% (- 3 (% n 3)) 3)) + (i (/ (+ n slop) 3)) + (rnum 0)) + (while (> i 0) + (setq rnum + (math-add + (math-random-three-digit-number) + (math-mul rnum 1000))) + (setq i (1- i))) + (math-normalize (math-scale-right rnum slop)))) ;;; Produce a uniformly-distributed random float 0 <= N < 1. (defun math-random-float () |