Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
ansi-test
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
5
Merge Requests
5
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ansi-test
ansi-test
Commits
fb346e77
Commit
fb346e77
authored
May 27, 2004
by
nobody
Browse files
Options
Browse Files
Download
Plain Diff
This commit was manufactured by cvs2svn to create branch 'Version_2_6_2pre'.
parents
c5827567
2ef47e5f
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2205 additions
and
0 deletions
+2205
-0
ansi-tests/random-aux.lsp
ansi-tests/random-aux.lsp
+90
-0
ansi-tests/random-int-form.lsp
ansi-tests/random-int-form.lsp
+2115
-0
No files found.
ansi-tests/random-aux.lsp
0 → 100644
View file @
fb346e77
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Jun 8 06:56:15 2003
;;;; Contains: Aux. functions and macros used for randomization
(in-package :cl-test)
(defun random-from-seq (seq)
"Generate a random member of a sequence."
(let ((len (length seq)))
(assert (> len 0))
(elt seq (random len))))
(defmacro random-case (&body cases)
(let ((len (length cases)))
(assert (> len 0))
`(case (random ,len)
,@(loop for i from 0 for e in cases collect `(,i ,e))
(t (error "Can't happen?! (in random-case)~%")))))
(defmacro rcase (&body cases)
"Usage: (RCASE (<weight> <form>+)+), where <weight> is a positive real
indicating the relative probability of executing the associated implicit
progn."
(assert cases)
(let* ((weights (mapcar #'car cases))
(cumulative-weights (let ((sum 0))
(loop for w in weights collect (incf sum w))))
(total (car (last cumulative-weights)))
(r (gensym)))
(assert (every #'plusp weights))
`(let ((,r (random ,total)))
(cond
,@(loop for case in (butlast cases)
for cw in cumulative-weights
collect `((< ,r ,cw) ,@(cdr case)))
(t ,@(cdar (last cases)))))))
(defun random-nonnegative-real ()
(if (coin 3)
(random-case
(/ (random 10000) (1+ (random 1000)))
(/ (random 1000000) (1+ (random 100000)))
(/ (random 100000000) (1+ (random 10000000)))
(/ (random 1000000000000) (1+ (random 10000000))))
(random (random-case
1000
100000
10000000
1000000000
(expt 2.0s0 (random 15))
(expt 2.0f0 (random 32))
(expt 2.0d0 (random 32))
(expt 2.0l0 (random 32))))))
(defun random-real ()
(if (coin) (random-nonnegative-real)
(- (random-nonnegative-real))))
(defun random-fixnum ()
(+ (random (1+ (- most-positive-fixnum most-negative-fixnum)))
most-negative-fixnum))
(defun random-from-interval (upper &optional (lower (- upper)))
(+ (random (- upper lower)) lower))
(defun coin (&optional (n 2))
"Flip an n-sided coin."
(eql (random n) 0))
;;; Randomly permute a sequence
(defun random-permute (seq)
(setq seq (copy-seq seq))
(let ((len (length seq)))
(loop for i from len downto 2
do (let ((r (random i)))
(rotatef (elt seq r) (elt seq (1- i))))))
seq)
(defun binomial-distribution-test (n fn)
(let* ((count (loop repeat n count (funcall fn)))
(sigma (/ (sqrt n) 2.0))
(bound (* sigma 6))
(expected (/ n 2.0)))
(<= (- expected bound)
count
(+ expected bound))))
ansi-tests/random-int-form.lsp
0 → 100644
View file @
fb346e77
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment