Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 605747b2a2
...
compare: cb2dd02aeb
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 01, 2012
@PeterReid defconsts can be namespaced 8cbbf08
@PeterReid Random strings and symbols are generated faster
DrAcula chooses lengths of strings and symbols using a Bernoulli
distribution, so defrandom was as well. It was doing it by actually
simulating a bunch of independent trials and counting how many ended up
positive, which is how the distribution is actually defined, but that was
not very efficient. Now, it has hard-coded weights for the different
results and chooses from them, so it has to generate only one random
number instead of many.
cb2dd02
Showing with 22 additions and 11 deletions.
  1. +20 −10 doublecheck/defrandom.lisp
  2. +2 −1  doublecheck/namespace.lisp
View
30 doublecheck/defrandom.lisp
@@ -145,22 +145,32 @@
nil
(cons (random-char) (%random-char-list (1- n)))))
-(defrandom% %random-occurrence-count (tries occurred improb-power)
- (if (zp tries)
- occurred
- (%random-occurrence-count
- (1- tries)
- (+ occurred (if (equal (%random-below-2^n improb-power 0) 0) 1 0))
- improb-power)))
+(defconst% *%string-length-distribution*
+ '(179 879 1120 952 559 289 87 19 11 1))
+
+(make-event
+ `(defconst% *%string-length-distribution-sum*
+ (+ ,@*defrandom%string-length-distribution* )))
+
+(defun% %pick-from-distribution (distribution n idx )
+ (if (or (endp distribution) (< idx (first distribution)))
+ n
+ (%pick-from-distribution (rest distribution)
+ (1+ n)
+ (- idx (first distribution)))))
+
+(defrandom% %random-string-length ()
+ (%pick-from-distribution *%string-length-distribution* 0
+ (%random-below *%string-length-distribution-sum*)))
(defrandom% %string-of-length (n)
(coerce (%random-char-list n) 'string))
(defrandom% random-string ()
- (%string-of-length (%random-occurrence-count 300 0 6)))
+ (%string-of-length (%random-string-length)))
(defrandom% random-symbol ()
- (intern (string-upcase (%string-of-length (%random-occurrence-count 300 1 6))) "ACL2"))
+ (intern (string-upcase (%string-of-length (1+ (%random-string-length)))) "ACL2"))
(defun% %number-cases (cases n)
(if (endp cases)
@@ -256,4 +266,4 @@
(%random-sexp-of-size (random-data-size)))
(pop-namespace defrandom)
-
+
View
3  doublecheck/namespace.lisp
@@ -18,7 +18,7 @@
(intern-in-package-of-symbol
(concatenate 'string
"*"
- (symbol-name prefix)
+ prefix
(subseq name 1 (- (length name) 1))
"*") x))
@@ -73,6 +73,7 @@
`(defmacro ,form-name% (&rest args)
`(in-namespace (,',form-name ,@args)))))
+(def-namespace-form defconst)
(def-namespace-form defun)
(def-namespace-form defmacro)
(def-namespace-form encapsulate)

No commit comments for this range

Something went wrong with that request. Please try again.