From: Robert Feldt Date: 2001-11-28T08:34:52+09:00 Subject: [ruby-talk:26715] ANN: RandomR 0.1.0 Hi, Below is README for a small wrapper for a fast Mersenne Twister algorithm. Is a really good pseudo-random number generator, can be marshaled etc. This is an alpha release and only tested on a single platform. If you have problems then please mail me. I noted that someone just released a Ruby wrapper for Gnu Scientific library (GSL) which contains many more RNG's. However, the Mersenne Twister in there is not very fast. And I haven't checked if Ruby-GSL supports the RNG's either. But if you want a large variety of RNG's then Ruby-GSL might be your thing. RandomR focuses on a small and fast extensions that is better than Ruby's builtin RNG (which relies on the OS etc). Regards, Robert RandomR - Pseudo-random generators for Ruby =========================================== Version: 0.1.0 Release date: 2001-11-28 Home page: http://rubyvm.sf.net/subprojects/randomr Tarball: http://prdownloads.sf.net/rubyvm/randomr-0-1-0.tar.gz Author: Robert Feldt Email: feldt@ce.chalmers.se What is it? ----------- Pseudo-random number generators (PRNG) for Ruby. Includes a very fast C implementation of the Mersenne Twister, which is a very good PRNG. It has a period of 2**19937-1 and is equi-distributed in 623 dimensions! Why? ---- Ruby's rand/srand have a number of drawbacks: * Global * No way to have independent sequences in different threads * Cannot be marshaled * OS-dependent low-level implementation * The actual PRNG alg used varies between platforms * The actual PRNG alg used are often old algorithms giving not-so-good randomness * The random sequence generated varies between platforms (Not good when you want random numbers but from a defined sequence, common in simulations and evolutionary computation) * Not crypto-safe RandomR addresses all these problems but the crypto-safety which is still on the todo. Installation? ------------- 1. unpack tarball (if you haven't already) 2. ruby make.rb 3. ruby install.rb Example of use? --------------- require 'random/mersenne_twister' mt = Random::MersenneTwister.new 4357 mt.rand(0) # => 0.424325522 mt.rand(10) # => 9 Requirements? ------------- ANSI C compiler and Ruby. I've successfully used RandomR with Ruby 1.7.1 (2001-09-20) and cygwin 1.1.8 (gcc version 2.95.2-5 19991024) on Windows 2000 Professional Workstation. If it works for you on other platforms/setups I'd appreciate if you drop me a note. However, it should work on most Ruby-enabled platforms having a C compiler. NOTE THAT THIS IS AN ALPHA RELEASE SO THERE MIGHT BE BUGS. Documentation? -------------- None yet. The API is very simple and can be found in the file random.rb. Also check out the tests. For the future? --------------- Maybe crypto-strong randomness generation and more algorithms but its not a high priority. Focus in on getting the API right and the MersenneTwister really fast and correct. I think we're close on all these aspects with this version 0.2.0. License and legal issues? ------------------------- RandomR is Copyright (c) 2001 Robert Feldt, feldt@ce.chalmers.se All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA The code for the Mersenne Twister is based on MersenneTwister.h by Richard Wagner. The original code included the following notice: Copyright (C) 2001 Richard J. Wagner The original code included the following notice: Copyright (C) 1997, 1999 Makoto Matsumoto and Takuji Nishimura. When you use this, send an email to: matumoto@math.keio.ac.jp with an appropriate reference to your work. It would be nice to CC: rjwagner@writeme.com and Cokus@math.washington.edu when you write. Do you have comments or questions? ---------------------------------- I'd appreciate if you drop me a note if you're successfully using RandomR. If there are some known users I'll be more motivated to packing up additions / new versions and post them to RAA. Happy coding! Robert Feldt, feldt@ce.chalmers.se