((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/random-swb" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg")) (section 2 "swb-random" (p "A random number generator based on the subtract-with-borrow (SWB) method.") (toc)) (section 2 "Usage" (p "(require-extension swb-random)")) (section 2 "Documentation" (p "The swb-random library is a port of the SML/NJ implementation of a random number generator using the subtract-with-borrow (SWB) method described by Marsaglia and Zaman in") (pre "A New Class of Random Number Generators, Ann. Applied Prob. 1(3), 1991, pp. 462-480. ") (p "The SWB generator implemented in this library is a 30-bit generator with lags 48 and 8. It has period " (tt "(2^1487 - 2^247)/105") " or about " (tt "10^445") ". The SWB generator acts locally like a lagged Fibonacci generator and thus it is combined with a linear congruential generator " (tt "(48271*a)mod(2^30-1)") ".") (section 3 "Procedures" (def (sig (procedure "make-swb-random-state:: CONG-SEED SHR-SEED -> SWB-STATE" (id make-swb-random-state))) (p "Creates an initial seed array and generator state. The seed vector is filled one bit at a time by taking the leading bit of the xor of a shift register and a congruential sequence.  The congruential generator is " (tt "(c*48271) mod (2^30 - 1)") ". The shift register generator is " (tt "c(I + L18)(I + R13)") ".  The same congruential generator continues to be used as a mixing generator with the SWB generator.")) (def (sig (procedure "swb-random!:: SWB-STATE -> FIXNUM" (id swb-random!))) (p "Computes the next random number. The output from the SWB generator is xor-ed with a number from the linear congruential generator. This procedure modifies its input argument.")) (def (sig (procedure "swb-random-natural!:: SWB-STATE -> FIXNUM" (id swb-random-natural!))) (p "Computes the next random number and returns its absolute value. The output from the SWB generator is xor-ed with a number from the linear congruential generator. This procedure modifies its input argument.")) (def (sig (procedure "swb-random-real!:: SWB-STATE -> FLONUM" (id swb-random-real!))) (p "Computes the two next random numbers and uses them to construct a real number of the range " (tt "[0..1]") ". The output from the SWB generator is xor-ed with a number from the linear congruential generator. This procedure modifies its input argument.")) (def (sig (procedure "swb-random-range!:: (FIXNUM * FIXNUM) -> (SWB-STATE -> FIXNUM)" (id swb-random-range!))) (p "Given a range " (tt "[i..j], 0 <= i < j") ", returns a procedure that takes in a random number generator state and computes a random number in the given range. The output from the SWB generator is xor-ed with a number from the linear congruential generator. The returned procedure modifies its input argument.")) (def (sig (procedure "swb-random:: SWB-STATE -> SWB-STATE * FIXNUM" (id swb-random))) (p "Computes the next random number. The output from the SWB generator is xor-ed with a number from the linear congruential generator. The new generator state is returned along with the random number.")) (def (sig (procedure "swb-random-natural:: SWB-STATE -> SWB-STATE * FIXNUM" (id swb-random-natural))) (p "Computes the next random number and returns its absolute values. The output from the SWB generator is xor-ed with a number from the linear congruential generator. The new generator state is returned along with the random number.")) (def (sig (procedure "swb-random-real:: SWB-STATE -> SWB-STATE * FLONUM" (id swb-random-real))) (p "Computes the two next random numbers and uses them to construct a real number of the range " (tt "[0..1]") ". The output from the SWB generator is xor-ed with a number from the linear congruential generator. The new generator state is returned along with the random number.")) (def (sig (procedure "swb-random-range:: (FIXNUM * FIXNUM) -> (SWB-STATE -> SWB-STATE * FIXNUM)" (id swb-random-range))) (p "Given a range " (tt "[i..j], 0 <= i < j") ", returns a procedure that takes in a random number generator state and computes a random number in the given range. The output from the SWB generator is xor-ed with a number from the linear congruential generator. The new generator state is returned along with the random number.")))) (section 2 "About this egg" (section 3 "Author" (p (int-link "/users/ivan-raikov" "Ivan Raikov"))) (section 3 "Version history" (dl (dt "1.12") (dd "Documentation converted to wiki format") (dt "1.11") (dd "Added import of foreign library [thanks to felix]") (dt "1.9") (dd "Added matchable as a dependency") (dt "1.8") (dd "Bug fix in interface to cminus function") (dt "1.7") (dd "Ported to Chicken 4") (dt "1.5") (dd "Bug fix in the setup file") (dt "1.4") (dd "Removed easyffi dependency") (dt "1.3") (dd "Build script updated for better cross-platform compatibility") (dt "1.2") (dd "Fixed the .meta file to include the documentation") (dt "1.1") (dd "License upgrade to GPL v3") (dt "1.0") (dd "Initial release"))) (section 3 "License" (pre "Copyright 2007-2010 Ivan Raikov. \n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or (at\nyour option) any later version.\n\nThis program is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\nGeneral Public License for more details.\n\nA full copy of the GPL license can be found at\n<http://www.gnu.org/licenses/>."))))