aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/calc/calc-comb.el25
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 @@
615;;; Avoid various pitfalls that may lurk in the built-in (random) function! 615;;; Avoid various pitfalls that may lurk in the built-in (random) function!
616;;; Shuffling algorithm from Numerical Recipes, section 7.1. 616;;; Shuffling algorithm from Numerical Recipes, section 7.1.
617(defvar math-random-last) 617(defvar math-random-last)
618(defun math-random-digit () 618(defun math-random-three-digit-number ()
619 "Return a random three digit number."
619 (let (i) 620 (let (i)
620 (or (and (boundp 'var-RandSeed) (eq var-RandSeed math-last-RandSeed)) 621 (or (and (boundp 'var-RandSeed) (eq var-RandSeed math-last-RandSeed))
621 (math-init-random-base)) 622 (math-init-random-base))
@@ -635,17 +636,17 @@
635 636
636;;; Produce an N-digit random integer. 637;;; Produce an N-digit random integer.
637(defun math-random-digits (n) 638(defun math-random-digits (n)
638 (cond ((<= n 6) 639 "Produce a random N digit integer."
639 (math-scale-right (+ (* (math-random-digit) 1000) (math-random-digit)) 640 (let* ((slop (% (- 3 (% n 3)) 3))
640 (- 6 n))) 641 (i (/ (+ n slop) 3))
641 (t (let* ((slop (% (- 900003 n) 3)) 642 (rnum 0))
642 (i (/ (+ n slop) 3)) 643 (while (> i 0)
643 (digs nil)) 644 (setq rnum
644 (while (> i 0) 645 (math-add
645 (setq digs (cons (math-random-digit) digs) 646 (math-random-three-digit-number)
646 i (1- i))) 647 (math-mul rnum 1000)))
647 (math-normalize (math-scale-right (cons 'bigpos digs) 648 (setq i (1- i)))
648 slop)))))) 649 (math-normalize (math-scale-right rnum slop))))
649 650
650;;; Produce a uniformly-distributed random float 0 <= N < 1. 651;;; Produce a uniformly-distributed random float 0 <= N < 1.
651(defun math-random-float () 652(defun math-random-float ()