unittest cleanup.
[CommonLispStat.git] / random.lisp
blob338dfd4e5a4f97dc47ce5a38d788ab99e821a08f
1 ;;; -*- mode: lisp -*-
3 ;;; File: random.lisp
4 ;;; Author: AJ Rossini <blindglobe@gmail.com>
5 ;;; Copyright: (c)2008, AJ Rossini. BSD, LLGPL, or GPLv2, depending
6 ;;; on how it arrives.
7 ;;; Purpose: random number streams, serial and parallel
8 ;;; Time-stamp: <2008-03-11 19:18:48 user>
9 ;;; Creation: <2008-03-11 19:18:34 user>
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 ;;; This organization and structure is new to the 21st Century
16 ;;; version.
18 ;;; Lispy implementation of random numbers. Initially, we leverage
19 ;;; existing code before "improving" (which is an ill-definded action
20 ;;; to do).
22 (in-package :cl-user)
24 (defpackage :lisp-stat-random
25 (:use :common-lisp)
26 (:export *seed* rng
27 variate
28 quantile
29 probability-density-function cumulative-density-function
30 probability-types))
32 (in-package :lisp-stat-random)
34 (defstruct probability-types
35 (list (1 . normal)
36 (2 . t)
37 (3 . cauchy)
38 (4 . gamma)))
40 (defvar *seed* nil
41 "Current global state of all pRNGs that might be active. This needs
42 to be aware that it should be thread-safe, so might be a list of
43 indexible triples.")
45 (defvar *current-rng* nil
46 "How do we understand this in a thread-safe manner?")
48 (defun rng-seed (&opt value specification)
49 "For getting and setting a particular rng with a particular seed,
50 Returns the current seed, even (especially!) if there is nothing to
51 set."
52 (if (and specification value)
53 (progn
54 (set-rng-type specification)
55 (if value (setf *seed* value)))
56 (if value (setf *seed* value)))
57 *seed*)