Commit c72f51dd authored by liam's avatar liam

Use random number generators inside with-gsl-objects.


git-svn-id: svn+ssh://pop/opt/space/mathematics/gsl/trunk@3278 a3d8a0fb-c1db-0310-ace7-a616afeb9e30
parent ac62a39f
;; Generators of random numbers.
;; Liam Healy, Sat Jul 15 2006 - 14:43
;; Time-stamp: <2008-01-21 11:47:49EST generators.lisp>
;; Time-stamp: <2008-01-31 22:43:53EST generators.lisp>
;; $Id: $
(in-package :gsl)
......@@ -38,6 +38,8 @@
:generator generator)))
(if (eq generator t) (alloc instance) instance)))
(set-asf random-number-generator make-random-number-generator free rng-set 1)
;;;;****************************************************************************
;;;; Initialization
;;;;****************************************************************************
......@@ -248,18 +250,18 @@
(lisp-unit:define-test random-number-generators
(lisp-unit:assert-equal
'(999 162 282 947 231 484 957 744 540 739 759)
(progn
(rng-set *rng-mt19937* 0)
(with-gsl-objects ((random-number-generator rng *mt19937* 0))
(loop for i from 0 to 10
collect
(uniform-fixnum *rng-mt19937* 1000))))
collect
(uniform-fixnum rng 1000))))
(lisp-unit:assert-equal
'("0.111776229978d+00" "0.959166794996d+00" "0.841526801158d+00"
"0.925403713680d+00" "0.275406984741d+00" "0.709304057392d+00"
"0.554133304187d+00" "0.880695776958d+00" "0.597139396983d+00"
"0.751874113340d+00" "0.931108462127d+00")
(lisp-unit:fp-sequence
(progn
(rng-set *rng-cmrg* 0)
(loop for i from 0 to 10
collect (uniform *rng-cmrg*))))))
(with-gsl-objects ((random-number-generator rng *cmrg* 0))
(loop for i from 0 to 10 collect (uniform rng))))))
;; Quasi-random sequences in arbitrary dimensions.
;; Liam Healy, Sun Jul 16 2006 - 15:54
;; Time-stamp: <2008-01-21 11:39:10EST quasi.lisp>
;; Time-stamp: <2008-01-31 22:52:29EST quasi.lisp>
;; $Id: $
(in-package :gsl)
......@@ -11,6 +11,9 @@
(defparameter *default-quasi-random-number-generator* nil)
(set-asf quasi-random-number-generator
make-quasi-random-number-generator free nil 2)
(defun make-quasi-random-number-generator
(dimension
&optional (type *default-quasi-random-number-generator*)
......@@ -126,10 +129,9 @@
(lisp-unit:assert-equal
'(0.5d0 0.5d0 0.75d0 0.25d0 0.25d0 0.75d0 0.375d0 0.375d0 0.875d0 0.875d0)
(with-data (vec vector-double 2)
(let ((gen (make-quasi-random-number-generator 2 *sobol*)))
(init gen)
(prog1
(loop repeat 5
do (qrng-get gen vec)
append (coerce (data vec) 'list))
(free gen))))))
(with-gsl-objects ((quasi-random-number-generator gen 2 *sobol*))
(loop repeat 5
do (qrng-get gen vec)
append (coerce (data vec) 'list))))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment