Math-Random-TT800-1.01/0040750000175000017500000000000007555544602013310 5ustar lendllendlMath-Random-TT800-1.01/tt800.h0100644000175000017500000000052106317446603014335 0ustar lendllendl #define TT800_N 25 #define TT800_M 7 #define TT800_INV_MOD 2.3283064370807974e-10 /* 1.0 / (2^32-1) */ struct tt800_state { U32 x[TT800_N]; /* make use of the perl type */ int k; }; typedef struct tt800_state *TT800; extern struct tt800_state tt800_initial_state; U32 tt800_get_next_int(TT800 g); Math-Random-TT800-1.01/README0100644000175000017500000000133107555543636014176 0ustar lendllendl This perl extension module implements M. Matsumoto's twisted generalized shift register generator called TT800 as described in his article published in ACM Transactions on Modelling and Computer Simulation, Vol. 4, No. 3, 1994, pages 254-266. This implementation is based on the C code by M. Matsumoto available from ftp://random.mat.sbg.ac.at/pub/data/tt800.c. Converted to a perl extension module and enhancements to support multiple streams of pseudorandom numbers by Otmar Lendl . Copyright (c) 1997 by Otmar Lendl (Perl and XS code). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Math-Random-TT800-1.01/MANIFEST0100644000175000017500000000014607555544473014452 0ustar lendllendlChanges MANIFEST COPYRIGHT README Makefile.PL TT800.pm TT800.xs test.pl typemap tt800_core.c tt800.h Math-Random-TT800-1.01/test.pl0100644000175000017500000000303207555541735014630 0ustar lendllendl# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..9\n"; } END {print "not ok 1\n" unless $loaded;} use Math::Random::TT800; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): # # Testing with default seed # $tt = new Math::Random::TT800; (sprintf("%u",$tt->next_int()) eq "3169973338") or print "not "; print "ok 2\n"; (abs($tt->next() - 0.63445952502881) < 0.0000001 ) or print "not "; print "ok 3\n"; for (1..100) { $tt->next_int(); } (sprintf("%u",$tt->next_int()) eq "3491672134") or print "not "; print "ok 4\n"; (abs($tt->next() - 0.25527860719135) < 0.0000001 ) or print "not "; print "ok 5\n"; # # Testing with custom seed # $tt = new Math::Random::TT800 42,1,8,1,4,131,91231,9173123; (sprintf("%u",$tt->next_int()) eq "42010539") or print "not "; print "ok 6\n"; (abs($tt->next() - 2.3283064370808e-10) < 0.0000001 ) or print "not "; print "ok 7\n"; for (1..100) { $tt->next_int(); } (sprintf("%u",$tt->next_int()) eq "2788880872") or print "not "; print "ok 8\n"; (abs($tt->next() - 0.625562964851401) < 0.0000001 ) or print "not "; print "ok 9\n"; Math-Random-TT800-1.01/TT800.pm0100644000175000017500000000347607555543765014452 0ustar lendllendlpackage Math::Random::TT800; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; require DynaLoader; @ISA = qw(Exporter DynaLoader); @EXPORT = qw(); @EXPORT_OK = qw(); $VERSION = '1.01'; bootstrap Math::Random::TT800 $VERSION; 1; __END__ =head1 NAME Math::Random::TT800 - Matsumoto's TT800 Pseudorandom number generator =head1 DESCRIPTION This perl extension module implements M. Matsumoto's twisted generalized shift register generator called TT800 as described in his article published in ACM Transactions on Modelling and Computer Simulation, Vol. 4, No. 3, 1994, pages 254-266. =head1 SYNOPSIS use Math::Random::TT800; my $tt = new Math::Random::TT800; $value = $tt->next(); $ivalue = $tt->next_int(); =head1 FUNCTIONS =over 4 =item new my $tt = new Math::Random::TT800; my $tt = new Math::Random::TT800 @seeds; Create a new TT800 object. Providing seeds is optional. A TT800 takes 25 integers as seed which must not be all zero. If less than 25 integers are supplied, the rest are taken from the default seed. =item next $value = $tt->next(); next returns the next pseudorandom number from the TT800 object as a floating point value in the range [0,1). =item next_int $ivalue = $tt->next_int(); next_int returns a integer value filled with 32 random bits. =back =head1 COPYRIGHT This implementation is based on the C code by M. Matsumoto available from ftp://random.mat.sbg.ac.at/pub/data/tt800.c. Converted to a perl extension module and enhancements to support multiple streams of pseudorandom numbers by Otmar Lendl . Copyright (c) 1997 by Otmar Lendl (Perl and XS code). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Math-Random-TT800-1.01/COPYRIGHT0100644000175000017500000000057107555543704014612 0ustar lendllendl Orginal C implementation of the tt800 was published by M. Matsumoto . This Perl extension was written by Otmar Lendl (lendl@cosy.sbg.ac.at) for the Perl Journal. Copyright (c) 1997 by Otmar Lendl (Perl and XS code). All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Math-Random-TT800-1.01/typemap0100644000175000017500000000043707555541413014715 0ustar lendllendlTYPEMAP TT800 T_TT800 INPUT T_TT800 if (sv_isa($arg, \"Math::Random::TT800\")) { IV tmp = SvIV((SV*)SvRV($arg)); $var = ($type) tmp; } else croak(\"$var is not of type Math::Random::TT800\") OUTPUT T_TT800 sv_setref_pv($arg, \"Math::Random::TT800\", (void*)$var); Math-Random-TT800-1.01/tt800_core.c0100644000175000017500000000410606317523640015340 0ustar lendllendl/* A C-program for TT800 : July 8th 1996 Version */ /* by M. Matsumoto, email: matumoto@math.keio.ac.jp */ /* genrand() generate one pseudorandom number with double precision */ /* which is uniformly distributed on [0,1]-interval */ /* for each call. One may choose any initial 25 seeds */ /* except all zeros. */ /* See: ACM Transactions on Modelling and Computer Simulation, */ /* Vol. 4, No. 3, 1994, pages 254-266. */ /* we need 32 bits ore more for these numbers. 64 bits do not hurt. */ #include "EXTERN.h" #include "perl.h" #include "tt800.h" struct tt800_state tt800_initial_state = { { /* initial 25 seeds, */ 0x95f24dab, 0x0b685215, 0xe76ccae7, 0xaf3ec239, 0x715fad23, 0x24a590ad, 0x69e4b5ef, 0xbf456141, 0x96bc1b7b, 0xa7bdf825, 0xc1de75b7, 0x8858a9c9, 0x2da87693, 0xb657f9dd, 0xffdc8a9f, 0x8121da71, 0x8b823ecb, 0x885d05f5, 0x4e20cd47, 0x5a9ad5d9, 0x512c0c03, 0xea857ccd, 0x4cc1d30f, 0x8891a8a1, 0xa6b7aadb }, 0 /* initial k */ }; static unsigned int mag01[2]= { /* this is magic vector `a', don't change */ 0x0, 0x8ebfd028 }; /* * tt800_get_next_int: Return next TT800 number (unscaled) * * Input: * g: Pointer to a struct tt800_state. * */ U32 tt800_get_next_int(TT800 g) { U32 y; if (g->k == TT800_N) /* generate TT800_N words at one time */ { int kk; for (kk=0; kk < TT800_N - TT800_M; kk++) { g->x[kk] = g->x[kk+TT800_M] ^ (g->x[kk] >> 1) ^ mag01[g->x[kk] & 1]; } for (; kkx[kk] = g->x[kk+(TT800_M-TT800_N)] ^ (g->x[kk] >> 1) ^ mag01[g->x[kk] & 1]; } g->k=0; } y = g->x[g->k]; y ^= (y << 7) & 0x2b5b2500; /* s and b, magic vectors */ y ^= (y << 15) & 0xdb8b0000; /* t and c, magic vectors */ /* the following line was added by Makoto Matsumoto in the 1996 version to improve lower bit's corellation. Delete this line to o use the code published in 1994. */ g->k++; y ^= (y >> 16); /* added to the 1994 version */ return(y); } Math-Random-TT800-1.01/Changes0100644000175000017500000000050507555544464014613 0ustar lendllendlRevision history for Perl extension Math::(Random)::TT800. 0.01 Sun Mar 30 11:26:24 1997 - original version; created by h2xs 1.16 1.00 Sun Mar 30 17:02:50 MET DST 1997 - finished version. 1.01 Wed Oct 23 17:36:34 CEST 2002 - renamed to Math::Random::TT800 - removed TT800.c vs. tt800.c clash - initial CPAN upload Math-Random-TT800-1.01/Makefile.PL0100644000175000017500000000072007555544506015266 0ustar lendllendluse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Math::Random::TT800', 'DISTNAME' => 'Math-Random-TT800', 'VERSION_FROM' => 'TT800.pm', # finds $VERSION 'OBJECT' => 'TT800.o tt800_core.o', 'LIBS' => [''], # e.g., '-lm' 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' 'INC' => '', # e.g., '-I/usr/include/other' ); Math-Random-TT800-1.01/TT800.xs0100644000175000017500000000152307555541340014442 0ustar lendllendl#ifdef __cplusplus extern "C" { #endif #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include #ifdef __cplusplus } #endif #include "tt800.h" MODULE = Math::Random::TT800 PACKAGE = Math::Random::TT800 TT800 new(class = "Math::Random::TT800", ...) char * class CODE: { int i; RETVAL = (TT800) safemalloc(sizeof(struct tt800_state)); memcpy(RETVAL,(char * ) &tt800_initial_state, sizeof(struct tt800_state)); if ( items > (TT800_N + 1)) items = TT800_N + 1; for (i = 1; i < items; i++) RETVAL->x[i-1] = (U32) SvIV(ST(i)); } OUTPUT: RETVAL void DESTROY(tt) TT800 tt CODE: safefree((char *) tt); U32 next_int(tt) TT800 tt CODE: RETVAL = tt800_get_next_int(tt); OUTPUT: RETVAL double next(tt) TT800 tt CODE: RETVAL = tt800_get_next_int(tt) * TT800_INV_MOD; OUTPUT: RETVAL