summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2019-11-13 23:07:52 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2019-11-13 23:07:52 +0000
commitde3984078547ca7aa18e0b77c0a98f5da1548a84 (patch)
treedae18ae4d7b1dab633be55df6c2cd4027bd5f00e
parentbba1e93059cd8917941fb8f2ddfd03ad1dac4a99 (diff)
install a pseudo random number generator
git-svn-id: svn://tug.org/texlive/trunk@52782 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Build/source/texk/dvipdfm-x/ChangeLog13
-rw-r--r--Build/source/texk/dvipdfm-x/Makefile.am1
-rw-r--r--Build/source/texk/dvipdfm-x/Makefile.in55
-rw-r--r--Build/source/texk/dvipdfm-x/README50
-rwxr-xr-xBuild/source/texk/dvipdfm-x/configure22
-rw-r--r--Build/source/texk/dvipdfm-x/configure.ac2
-rw-r--r--Build/source/texk/dvipdfm-x/mem.h9
-rw-r--r--Build/source/texk/dvipdfm-x/mt19937ar.c192
8 files changed, 307 insertions, 37 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog
index 3c9960612e2..c75905bd4ac 100644
--- a/Build/source/texk/dvipdfm-x/ChangeLog
+++ b/Build/source/texk/dvipdfm-x/ChangeLog
@@ -1,3 +1,16 @@
+2019-11-14 Akira Kakuto <kakuto@w32tex.org>
+
+ * mt19937ar.c: Add to support common font names in all
+ platforms when SOURCE_DATE_EPOCH is suitably set. A pseudo
+ random number generating program coded by Takuji Nishimura and
+ Makoto Matsumoto.
+ * README: Add a subject "11. Random number generating function".
+ * mem.h: Add "#define srand(x) init_genrand((x))", etc. because
+ it is the only common header file for dpxcrypt.c, pdfencrypt.c,
+ and pdffont.c, which use rand().
+ * Makefile.am: Add mt19937ar.c.
+ * configure.ac: Version 20191114.
+
2019-11-13 Akira Kakuto <kakuto@w32tex.org>
* spc_dvips.c: Add -dDELAYSAFER in GS_CALCULATOR because
diff --git a/Build/source/texk/dvipdfm-x/Makefile.am b/Build/source/texk/dvipdfm-x/Makefile.am
index 1d8fc052b28..64f03ea3e8d 100644
--- a/Build/source/texk/dvipdfm-x/Makefile.am
+++ b/Build/source/texk/dvipdfm-x/Makefile.am
@@ -69,6 +69,7 @@ xdvipdfmx_SOURCES = \
mfileio.h \
mpost.c \
mpost.h \
+ mt19937ar.c \
numbers.c \
numbers.h \
otl_opt.c \
diff --git a/Build/source/texk/dvipdfm-x/Makefile.in b/Build/source/texk/dvipdfm-x/Makefile.in
index f0d359ba053..dbba58c3359 100644
--- a/Build/source/texk/dvipdfm-x/Makefile.in
+++ b/Build/source/texk/dvipdfm-x/Makefile.in
@@ -144,22 +144,22 @@ am_xdvipdfmx_OBJECTS = agl.$(OBJEXT) bmpimage.$(OBJEXT) cff.$(OBJEXT) \
dvi.$(OBJEXT) dvipdfmx.$(OBJEXT) epdf.$(OBJEXT) \
error.$(OBJEXT) fontmap.$(OBJEXT) jp2image.$(OBJEXT) \
jpegimage.$(OBJEXT) mem.$(OBJEXT) mfileio.$(OBJEXT) \
- mpost.$(OBJEXT) numbers.$(OBJEXT) otl_opt.$(OBJEXT) \
- pdfcolor.$(OBJEXT) pdfdev.$(OBJEXT) pdfdoc.$(OBJEXT) \
- pdfdraw.$(OBJEXT) pdfencrypt.$(OBJEXT) pdfencoding.$(OBJEXT) \
- pdffont.$(OBJEXT) pdfnames.$(OBJEXT) pdfobj.$(OBJEXT) \
- pdfparse.$(OBJEXT) pdfresource.$(OBJEXT) pdfximage.$(OBJEXT) \
- pkfont.$(OBJEXT) pngimage.$(OBJEXT) pst.$(OBJEXT) \
- pst_obj.$(OBJEXT) sfnt.$(OBJEXT) spc_color.$(OBJEXT) \
- spc_dvipdfmx.$(OBJEXT) spc_dvips.$(OBJEXT) spc_html.$(OBJEXT) \
- spc_misc.$(OBJEXT) spc_pdfm.$(OBJEXT) spc_tpic.$(OBJEXT) \
- spc_util.$(OBJEXT) spc_xtx.$(OBJEXT) specials.$(OBJEXT) \
- subfont.$(OBJEXT) t1_char.$(OBJEXT) t1_load.$(OBJEXT) \
- tfm.$(OBJEXT) truetype.$(OBJEXT) tt_aux.$(OBJEXT) \
- tt_cmap.$(OBJEXT) tt_glyf.$(OBJEXT) tt_gsub.$(OBJEXT) \
- tt_post.$(OBJEXT) tt_table.$(OBJEXT) type0.$(OBJEXT) \
- type1.$(OBJEXT) type1c.$(OBJEXT) unicode.$(OBJEXT) \
- vf.$(OBJEXT) xbb.$(OBJEXT)
+ mpost.$(OBJEXT) mt19937ar.$(OBJEXT) numbers.$(OBJEXT) \
+ otl_opt.$(OBJEXT) pdfcolor.$(OBJEXT) pdfdev.$(OBJEXT) \
+ pdfdoc.$(OBJEXT) pdfdraw.$(OBJEXT) pdfencrypt.$(OBJEXT) \
+ pdfencoding.$(OBJEXT) pdffont.$(OBJEXT) pdfnames.$(OBJEXT) \
+ pdfobj.$(OBJEXT) pdfparse.$(OBJEXT) pdfresource.$(OBJEXT) \
+ pdfximage.$(OBJEXT) pkfont.$(OBJEXT) pngimage.$(OBJEXT) \
+ pst.$(OBJEXT) pst_obj.$(OBJEXT) sfnt.$(OBJEXT) \
+ spc_color.$(OBJEXT) spc_dvipdfmx.$(OBJEXT) spc_dvips.$(OBJEXT) \
+ spc_html.$(OBJEXT) spc_misc.$(OBJEXT) spc_pdfm.$(OBJEXT) \
+ spc_tpic.$(OBJEXT) spc_util.$(OBJEXT) spc_xtx.$(OBJEXT) \
+ specials.$(OBJEXT) subfont.$(OBJEXT) t1_char.$(OBJEXT) \
+ t1_load.$(OBJEXT) tfm.$(OBJEXT) truetype.$(OBJEXT) \
+ tt_aux.$(OBJEXT) tt_cmap.$(OBJEXT) tt_glyf.$(OBJEXT) \
+ tt_gsub.$(OBJEXT) tt_post.$(OBJEXT) tt_table.$(OBJEXT) \
+ type0.$(OBJEXT) type1.$(OBJEXT) type1c.$(OBJEXT) \
+ unicode.$(OBJEXT) vf.$(OBJEXT) xbb.$(OBJEXT)
xdvipdfmx_OBJECTS = $(am_xdvipdfmx_OBJECTS)
xdvipdfmx_LDADD = $(LDADD)
xdvipdfmx_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
@@ -220,15 +220,16 @@ am__depfiles_remade = ./$(DEPDIR)/agl.Po ./$(DEPDIR)/bmpimage.Po \
./$(DEPDIR)/error.Po ./$(DEPDIR)/fontmap.Po \
./$(DEPDIR)/jp2image.Po ./$(DEPDIR)/jpegimage.Po \
./$(DEPDIR)/mem.Po ./$(DEPDIR)/mfileio.Po ./$(DEPDIR)/mpost.Po \
- ./$(DEPDIR)/numbers.Po ./$(DEPDIR)/otl_opt.Po \
- ./$(DEPDIR)/pdfcolor.Po ./$(DEPDIR)/pdfdev.Po \
- ./$(DEPDIR)/pdfdoc.Po ./$(DEPDIR)/pdfdraw.Po \
- ./$(DEPDIR)/pdfencoding.Po ./$(DEPDIR)/pdfencrypt.Po \
- ./$(DEPDIR)/pdffont.Po ./$(DEPDIR)/pdfnames.Po \
- ./$(DEPDIR)/pdfobj.Po ./$(DEPDIR)/pdfparse.Po \
- ./$(DEPDIR)/pdfresource.Po ./$(DEPDIR)/pdfximage.Po \
- ./$(DEPDIR)/pkfont.Po ./$(DEPDIR)/pngimage.Po \
- ./$(DEPDIR)/pst.Po ./$(DEPDIR)/pst_obj.Po ./$(DEPDIR)/sfnt.Po \
+ ./$(DEPDIR)/mt19937ar.Po ./$(DEPDIR)/numbers.Po \
+ ./$(DEPDIR)/otl_opt.Po ./$(DEPDIR)/pdfcolor.Po \
+ ./$(DEPDIR)/pdfdev.Po ./$(DEPDIR)/pdfdoc.Po \
+ ./$(DEPDIR)/pdfdraw.Po ./$(DEPDIR)/pdfencoding.Po \
+ ./$(DEPDIR)/pdfencrypt.Po ./$(DEPDIR)/pdffont.Po \
+ ./$(DEPDIR)/pdfnames.Po ./$(DEPDIR)/pdfobj.Po \
+ ./$(DEPDIR)/pdfparse.Po ./$(DEPDIR)/pdfresource.Po \
+ ./$(DEPDIR)/pdfximage.Po ./$(DEPDIR)/pkfont.Po \
+ ./$(DEPDIR)/pngimage.Po ./$(DEPDIR)/pst.Po \
+ ./$(DEPDIR)/pst_obj.Po ./$(DEPDIR)/sfnt.Po \
./$(DEPDIR)/spc_color.Po ./$(DEPDIR)/spc_dvipdfmx.Po \
./$(DEPDIR)/spc_dvips.Po ./$(DEPDIR)/spc_html.Po \
./$(DEPDIR)/spc_misc.Po ./$(DEPDIR)/spc_pdfm.Po \
@@ -696,6 +697,7 @@ xdvipdfmx_SOURCES = \
mfileio.h \
mpost.c \
mpost.h \
+ mt19937ar.c \
numbers.c \
numbers.h \
otl_opt.c \
@@ -1024,6 +1026,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mfileio.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mpost.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mt19937ar.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/numbers.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/otl_opt.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pdfcolor.Po@am__quote@ # am--include-marker
@@ -1706,6 +1709,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/mem.Po
-rm -f ./$(DEPDIR)/mfileio.Po
-rm -f ./$(DEPDIR)/mpost.Po
+ -rm -f ./$(DEPDIR)/mt19937ar.Po
-rm -f ./$(DEPDIR)/numbers.Po
-rm -f ./$(DEPDIR)/otl_opt.Po
-rm -f ./$(DEPDIR)/pdfcolor.Po
@@ -1829,6 +1833,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/mem.Po
-rm -f ./$(DEPDIR)/mfileio.Po
-rm -f ./$(DEPDIR)/mpost.Po
+ -rm -f ./$(DEPDIR)/mt19937ar.Po
-rm -f ./$(DEPDIR)/numbers.Po
-rm -f ./$(DEPDIR)/otl_opt.Po
-rm -f ./$(DEPDIR)/pdfcolor.Po
diff --git a/Build/source/texk/dvipdfm-x/README b/Build/source/texk/dvipdfm-x/README
index 28e4d71a4a1..daf5be0eb4d 100644
--- a/Build/source/texk/dvipdfm-x/README
+++ b/Build/source/texk/dvipdfm-x/README
@@ -504,3 +504,53 @@ Contents
embedding from Japan Typography Association (in Japanese):
http://www.typography.or.jp/act/morals/moral4.html
+
+11. Random number generating function
+
+ Prefixes of font names are calculated by using a function which
+ generates pseudo random numbers. In order to obtain a unique
+ prefix on all platforms when current time is common, a special
+ function MT19937, coded by Takuji Nishimura and Makoto Matsumoto,
+ is used. The header of the C program by Takuji Nishimura and
+ Makoto Matsumoto is the following:
+
+ A C-program for MT19937, with initialization improved 2002/1/26.
+ Coded by Takuji Nishimura and Makoto Matsumoto.
+
+ Before using, initialize the state by using init_genrand(seed)
+ or init_by_array(init_key, key_length).
+
+ Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
+ 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.
+
+
+ Any feedback is very welcome.
+ http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
+ email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
diff --git a/Build/source/texk/dvipdfm-x/configure b/Build/source/texk/dvipdfm-x/configure
index 509f8551133..d976c93ff88 100755
--- a/Build/source/texk/dvipdfm-x/configure
+++ b/Build/source/texk/dvipdfm-x/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for dvipdfm-x (TeX Live) 20190824.
+# Generated by GNU Autoconf 2.69 for dvipdfm-x (TeX Live) 20191114.
#
# Report bugs to <dvipdfmx@tug.org>.
#
@@ -590,8 +590,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='dvipdfm-x (TeX Live)'
PACKAGE_TARNAME='dvipdfm-x--tex-live-'
-PACKAGE_VERSION='20190824'
-PACKAGE_STRING='dvipdfm-x (TeX Live) 20190824'
+PACKAGE_VERSION='20191114'
+PACKAGE_STRING='dvipdfm-x (TeX Live) 20191114'
PACKAGE_BUGREPORT='dvipdfmx@tug.org'
PACKAGE_URL=''
@@ -1350,7 +1350,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures dvipdfm-x (TeX Live) 20190824 to adapt to many kinds of systems.
+\`configure' configures dvipdfm-x (TeX Live) 20191114 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1421,7 +1421,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of dvipdfm-x (TeX Live) 20190824:";;
+ short | recursive ) echo "Configuration of dvipdfm-x (TeX Live) 20191114:";;
esac
cat <<\_ACEOF
@@ -1551,7 +1551,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-dvipdfm-x (TeX Live) configure 20190824
+dvipdfm-x (TeX Live) configure 20191114
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
@@ -2390,7 +2390,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by dvipdfm-x (TeX Live) $as_me 20190824, which was
+It was created by dvipdfm-x (TeX Live) $as_me 20191114, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
@@ -8077,7 +8077,7 @@ fi
# Define the identity of the package.
PACKAGE='dvipdfm-x--tex-live-'
- VERSION='20190824'
+ VERSION='20191114'
cat >>confdefs.h <<_ACEOF
@@ -14746,7 +14746,7 @@ Usage: $0 [OPTIONS]
Report bugs to <bug-libtool@gnu.org>."
lt_cl_version="\
-dvipdfm-x (TeX Live) config.lt 20190824
+dvipdfm-x (TeX Live) config.lt 20191114
configured by $0, generated by GNU Autoconf 2.69.
Copyright (C) 2011 Free Software Foundation, Inc.
@@ -16636,7 +16636,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by dvipdfm-x (TeX Live) $as_me 20190824, which was
+This file was extended by dvipdfm-x (TeX Live) $as_me 20191114, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -16706,7 +16706,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-dvipdfm-x (TeX Live) config.status 20190824
+dvipdfm-x (TeX Live) config.status 20191114
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
diff --git a/Build/source/texk/dvipdfm-x/configure.ac b/Build/source/texk/dvipdfm-x/configure.ac
index fad7dd83402..c3b39879eb7 100644
--- a/Build/source/texk/dvipdfm-x/configure.ac
+++ b/Build/source/texk/dvipdfm-x/configure.ac
@@ -7,7 +7,7 @@ dnl This file is free software; the copyright holder
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl
-AC_INIT([dvipdfm-x (TeX Live)], [20190824], [dvipdfmx@tug.org])
+AC_INIT([dvipdfm-x (TeX Live)], [20191114], [dvipdfmx@tug.org])
AC_PREREQ([2.65])
AC_CONFIG_SRCDIR([agl.c])
AC_CONFIG_AUX_DIR([../../build-aux])
diff --git a/Build/source/texk/dvipdfm-x/mem.h b/Build/source/texk/dvipdfm-x/mem.h
index 7ee4cbfd5b6..b2271c54fad 100644
--- a/Build/source/texk/dvipdfm-x/mem.h
+++ b/Build/source/texk/dvipdfm-x/mem.h
@@ -38,4 +38,13 @@ extern void *renew (void *p, uint32_t size);
#define RENEW(p,n,type) (type *) renew(p,((uint32_t)(n))*sizeof(type))
#define RELEASE(p) free(p)
+/*
+ * mem.h is not suitable for the following, but it is the only common
+ * header file for dpxcrypt.c, pdfencrypt.c, and pdffont.c, which use
+ * the function rand().
+ */
+extern void init_genrand(unsigned long long s);
+extern long genrand_int31(void);
+#define srand(x) init_genrand((x))
+#define rand() genrand_int31()
#endif /* _MEM_H_ */
diff --git a/Build/source/texk/dvipdfm-x/mt19937ar.c b/Build/source/texk/dvipdfm-x/mt19937ar.c
new file mode 100644
index 00000000000..fab87b924a5
--- /dev/null
+++ b/Build/source/texk/dvipdfm-x/mt19937ar.c
@@ -0,0 +1,192 @@
+/*
+ A C-program for MT19937, with initialization improved 2002/1/26.
+ Coded by Takuji Nishimura and Makoto Matsumoto.
+
+ Before using, initialize the state by using init_genrand(seed)
+ or init_by_array(init_key, key_length).
+
+ Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
+ 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.
+
+
+ Any feedback is very welcome.
+ http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
+ email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
+*/
+
+#include <stdio.h>
+
+/* Period parameters */
+#define N 624
+#define M 397
+#define MATRIX_A 0x9908b0dfUL /* constant vector a */
+#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
+#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
+
+static unsigned long mt[N]; /* the array for the state vector */
+static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
+
+/* initializes mt[N] with a seed */
+/* void init_genrand(unsigned long s) */
+void init_genrand(unsigned long long s)
+{
+ mt[0]= s & 0xffffffffUL;
+ for (mti=1; mti<N; mti++) {
+ mt[mti] =
+ (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
+ /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
+ /* In the previous versions, MSBs of the seed affect */
+ /* only MSBs of the array mt[]. */
+ /* 2002/01/09 modified by Makoto Matsumoto */
+ mt[mti] &= 0xffffffffUL;
+ /* for >32 bit machines */
+ }
+}
+
+/* initialize by an array with array-length */
+/* init_key is the array for initializing keys */
+/* key_length is its length */
+/* slight change for C++, 2004/2/26 */
+void init_by_array(unsigned long init_key[], int key_length)
+{
+ int i, j, k;
+ init_genrand(19650218UL);
+ i=1; j=0;
+ k = (N>key_length ? N : key_length);
+ for (; k; k--) {
+ mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
+ + init_key[j] + j; /* non linear */
+ mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
+ i++; j++;
+ if (i>=N) { mt[0] = mt[N-1]; i=1; }
+ if (j>=key_length) j=0;
+ }
+ for (k=N-1; k; k--) {
+ mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
+ - i; /* non linear */
+ mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
+ i++;
+ if (i>=N) { mt[0] = mt[N-1]; i=1; }
+ }
+
+ mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
+}
+
+/* generates a random number on [0,0xffffffff]-interval */
+unsigned long genrand_int32(void)
+{
+ unsigned long y;
+ static unsigned long mag01[2]={0x0UL, MATRIX_A};
+ /* mag01[x] = x * MATRIX_A for x=0,1 */
+
+ if (mti >= N) { /* generate N words at one time */
+ int kk;
+
+ if (mti == N+1) /* if init_genrand() has not been called, */
+ init_genrand(5489UL); /* a default initial seed is used */
+
+ for (kk=0;kk<N-M;kk++) {
+ y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
+ mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
+ }
+ for (;kk<N-1;kk++) {
+ y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
+ mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
+ }
+ y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
+ mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
+
+ mti = 0;
+ }
+
+ y = mt[mti++];
+
+ /* Tempering */
+ y ^= (y >> 11);
+ y ^= (y << 7) & 0x9d2c5680UL;
+ y ^= (y << 15) & 0xefc60000UL;
+ y ^= (y >> 18);
+
+ return y;
+}
+
+/* generates a random number on [0,0x7fffffff]-interval */
+long genrand_int31(void)
+{
+ return (long)(genrand_int32()>>1);
+}
+
+/* generates a random number on [0,1]-real-interval */
+double genrand_real1(void)
+{
+ return genrand_int32()*(1.0/4294967295.0);
+ /* divided by 2^32-1 */
+}
+
+/* generates a random number on [0,1)-real-interval */
+double genrand_real2(void)
+{
+ return genrand_int32()*(1.0/4294967296.0);
+ /* divided by 2^32 */
+}
+
+/* generates a random number on (0,1)-real-interval */
+double genrand_real3(void)
+{
+ return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
+ /* divided by 2^32 */
+}
+
+/* generates a random number on [0,1) with 53-bit resolution*/
+double genrand_res53(void)
+{
+ unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
+ return(a*67108864.0+b)*(1.0/9007199254740992.0);
+}
+/* These real versions are due to Isaku Wada, 2002/01/09 added */
+#ifdef TEST
+int main(void)
+{
+ int i;
+ unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4;
+ init_by_array(init, length);
+ printf("1000 outputs of genrand_int32()\n");
+ for (i=0; i<1000; i++) {
+ printf("%10lu ", genrand_int32());
+ if (i%5==4) printf("\n");
+ }
+ printf("\n1000 outputs of genrand_real2()\n");
+ for (i=0; i<1000; i++) {
+ printf("%10.8f ", genrand_real2());
+ if (i%5==4) printf("\n");
+ }
+ return 0;
+}
+#endif