random-mtzig
An implementation of the MT19937 random number generator with Marsaglia and Tang's Ziggurat algorithm to generate random numbers from a non-uniform distribution.
TOC »
Usage
(import random-mtzig)
Documentation
The random-mtzig library is Chicken Scheme wrapper for the MT19937 random number generator used in GNU Octave.
Procedures
- initprocedure
Creates an initial seed array and returns the corresponding generator state vector. If the optional SEED is not specified, the generator is initialized with a seed from /dev/urandom or with the current time in seconds. If SEED can be an integer or an u32vector.
- random!procedure
Returns a random integer value between 0 and the largest machine-representable unsigned integer on the current platform.
- randu!procedure
Returns a random value from a uniform distribution on the interval (0, 1).
- randn!procedure
Returns a random value from a normal (Gaussian) distribution, using Marsaglia and Tsang's Ziggurat algorithm to transform a uniform distribution into a normal one.
- rande!procedure
Returns a random value from an exponential distribution, using Marsaglia and Tsang's Ziggurat algorithm to transform a uniform distribution into an exponential one.
- randb!procedure
Returns a random value from a binomial distribution with N experiments and probability P.
- randp!procedure
Returns a random value from a Poisson distribution with mean value L.
- randu/f64!procedure
Returns an SRFI-4 f64 vector of random values from a uniform distribution on the interval (0, 1).
- randn/f64!procedure
Returns an SRFI-4 f64 vector of random values from a normal (Gaussian) distribution, using Marsaglia and Tsang's Ziggurat algorithm to transform a uniform distribution into a normal one.
- rande/f64!procedure
Returns an SRFI-4 f64 vector of random values from am exponential distribution, using Marsaglia and Tsang's Ziggurat algorithm to transform a uniform distribution into an exponential one.
- randb/f64!procedure
Returns an SRFI-4 f64 vector of random values from a binomial distribution with N experiments and probability P.
- randp/f64!procedure
Returns an SRFI-4 f64 vector of random values from a Poisson distribution with mean value L.
- randu/f32!procedure
Returns an SRFI-4 f32 vector of random values from a uniform distribution on the interval (0, 1).
- randn/f32!procedure
Returns an SRFI-4 f32 vector of random values from a normal (Gaussian) distribution, using Marsaglia and Tsang's Ziggurat algorithm to transform a uniform distribution into a normal one.
- rande/f32!procedure
Returns an SRFI-4 f32 vector of random values from am exponential distribution, using Marsaglia and Tsang's Ziggurat algorithm to transform a uniform distribution into an exponential one.
- randb/f32!procedure
Returns an SRFI-4 f32 vector of random values from a binomial distribution with N experiments and probability P.
- randb/f32!procedure
Returns an SRFI-4 f32 vector of random values from a Poisson distribution with mean value L.
Examples
csi> (import random-mtzig) csi> (define st (init 24)) csi> (randu/f64! 20 st) #f64(0.960017303335919 0.699512049949576 0.999867292623879 0.220067299782852 0.361056353964058 0.739840990209437 0.996455725089097 0.316346977790608 0.136544579823525 0.3839800101516 0.320519283565193 0.366414753083515 0.709651562588127 0.900142430523374 0.534115439197721 0.247293764909945 0.671806562577075 0.561729107313138 0.54255987670951 0.893447603694901)
About this egg
Author
Repository
https://github.com/iraikov/chicken-random-mtzig
Version history
- 4.0
- ported to CHICKEN 5
- 3.2
- using bind instead of easyffi
- 3.1
- Added #defines necessary to use NAN and M_PI from math.h
- 3.0
- Added procedures for generating random numbers from a Poisson distribution
- 2.9
- Documentation converted to wiki format
- 2.8
- Ported to Chicken 4
- 2.7
- Added binomial sampling procedures
- 2.6
- Build script updated for better cross-platform compatibility
- 2.5
- Example updated to match 2.0 API [thanks to Terrence Brannon]
- 2.4
- Bug fix in random-mtzig:f32vector-rande!
- 2.3
- C interface bug fixes
- 2.2
- Changed type definition for uint64_t so it doesn't collide with stdint.h
- 2.1
- Bug fix in init procedure for vector case
- 2.0
- Created reentrant interface
- 1.0
- Initial release
License
Chicken Scheme egg scripts and documentation Copyright 2007-2019 Ivan Raikov. Coded by Takuji Nishimura and Makoto Matsumoto. This is a faster version by taking Shawn Cokus's optimization, Matthe Bellew's simplification, Isaku Wada's real version. David Bateman added normal and exponential distributions following Marsaglia and Tang's Ziggurat algorithm. Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, Copyright (C) 2004, David Bateman All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.