2012-06-29 12:19 UTC+0200 Viktor Szakats (harbour syenar.net)

+ contrib/hbtinymt
  + contrib/hbtinymt/3rd
  + contrib/hbtinymt/3rd/tinymt
  + contrib/hbtinymt/3rd/tinymt/LICENSE.txt
  + contrib/hbtinymt/3rd/tinymt/tinymt.dif
  + contrib/hbtinymt/3rd/tinymt/tinymt.hbc
  + contrib/hbtinymt/3rd/tinymt/tinymt.hbp
  + contrib/hbtinymt/3rd/tinymt/tinymt.hbx
  + contrib/hbtinymt/3rd/tinymt/tinymt32.c
  + contrib/hbtinymt/3rd/tinymt/tinymt32.h
  + contrib/hbtinymt/3rd/tinymt/tinymt64.c
  + contrib/hbtinymt/3rd/tinymt/tinymt64.h
  + contrib/hbtinymt/core.c
  + contrib/hbtinymt/hbtinymt.hbc
  + contrib/hbtinymt/hbtinymt.hbp
  + contrib/hbtinymt/hbtinymt.hbx
  + contrib/hbtinymt/tests
  + contrib/hbtinymt/tests/hbmk.hbm
  + contrib/hbtinymt/tests/test32.prg
  + contrib/hbtinymt/tests/test64.prg
  * contrib/hbplist
  * INSTALL
    + hbtinymt and 3rd party dependency tinymt added.
      hbtinymt is borrowed from xhb with my additions
      and fixes: MT support, type fixes, redone 3rd party
      dependency and tinymt patch, Harbour make files,
      formatting, enabled 64-bit flavor of tinymt,
      implemented HB_TINYMT32_GENERATE_FLOAT01(),
      implemented wrappers for 64-bit tinymt API, added
      tests for new functions.
This commit is contained in:
Viktor Szakats
2012-06-29 10:20:55 +00:00
parent 2cd14f1d8a
commit 5586dc13f9
18 changed files with 1527 additions and 0 deletions

View File

@@ -16,6 +16,38 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-06-29 12:19 UTC+0200 Viktor Szakats (harbour syenar.net)
+ contrib/hbtinymt
+ contrib/hbtinymt/3rd
+ contrib/hbtinymt/3rd/tinymt
+ contrib/hbtinymt/3rd/tinymt/LICENSE.txt
+ contrib/hbtinymt/3rd/tinymt/tinymt.dif
+ contrib/hbtinymt/3rd/tinymt/tinymt.hbc
+ contrib/hbtinymt/3rd/tinymt/tinymt.hbp
+ contrib/hbtinymt/3rd/tinymt/tinymt.hbx
+ contrib/hbtinymt/3rd/tinymt/tinymt32.c
+ contrib/hbtinymt/3rd/tinymt/tinymt32.h
+ contrib/hbtinymt/3rd/tinymt/tinymt64.c
+ contrib/hbtinymt/3rd/tinymt/tinymt64.h
+ contrib/hbtinymt/core.c
+ contrib/hbtinymt/hbtinymt.hbc
+ contrib/hbtinymt/hbtinymt.hbp
+ contrib/hbtinymt/hbtinymt.hbx
+ contrib/hbtinymt/tests
+ contrib/hbtinymt/tests/hbmk.hbm
+ contrib/hbtinymt/tests/test32.prg
+ contrib/hbtinymt/tests/test64.prg
* contrib/hbplist
* INSTALL
+ hbtinymt and 3rd party dependency tinymt added.
hbtinymt is borrowed from xhb with my additions
and fixes: MT support, type fixes, redone 3rd party
dependency and tinymt patch, Harbour make files,
formatting, enabled 64-bit flavor of tinymt,
implemented HB_TINYMT32_GENERATE_FLOAT01(),
implemented wrappers for 64-bit tinymt API, added
tests for new functions.
2012-06-29 02:59 UTC+0200 Viktor Szakats (harbour syenar.net)
* src/rtl/gtwvt/gtwvt.c
* using TEXT( '\0' ) instead of 0

View File

@@ -384,6 +384,7 @@ HARBOUR
HB_WITH_QT=C:\Qt\include (version 4.5.0 or upper is required)
HB_WITH_SLANG= (on *nix systems)
HB_WITH_SQLITE3=C:\sqlite3 (defaults to locally hosted version if not found)
HB_WITH_TINYMT=C:\tinymt\tinymt (defaults to locally hosted version)
HB_WITH_WATT= (on MS-DOS systems)
HB_WITH_X11= (on *nix systems)
HB_WITH_XDIFF=C:\libxdiff-0.23\xdiff (defaults to locally hosted version if not found)
@@ -1668,6 +1669,8 @@ HARBOUR
(mingw official 4.4.0 or upper, or mingw tdm with dwarf2)
HB_WITH_SQLITE3 - sqlite3 [multiplatform, free, open-source]
http://www.sqlite.org/
HB_WITH_TINYMT - TinyMT (Mersenne Twister) [multiplatform, free, open-source]
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/TINYMT/
HB_WITH_WATT - Watt-32 (TCP/IP sockets) [dos, free, open-source]
http://home.broadpark.no/~gvanem/
HB_WITH_ZLIB - zlib [multiplatform, free, open-source]

View File

@@ -48,6 +48,7 @@ hbsqlit3/hbsqlit3.hbp # uses: sqlite3 (locally hosted)
hbssl/hbssl.hbp
hbtip/hbtip.hbp
hbtip/hbtipssl.hbp
hbtinymt/hbtinymt.hbp
hbtpathy/hbtpathy.hbp
hbunix/hbunix.hbp
hbwin/hbwin.hbp

View File

@@ -0,0 +1,29 @@
Copyright (c) 2011 Mutsuo Saito, Makoto Matsumoto, Hiroshima
University and The University of Tokyo. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
* Neither the name of the Hiroshima University nor the names of
its contributors may 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.

View File

@@ -0,0 +1,310 @@
diff -urN tinymt.orig\tinymt32.c tinymt\tinymt32.c
--- tinymt.orig\tinymt32.c Fri Jun 29 12:11:18 2012
+++ tinymt\tinymt32.c Fri Jun 29 12:11:18 2012
@@ -60,17 +60,18 @@
* @param seed a 32-bit unsigned integer used as a seed.
*/
void tinymt32_init(tinymt32_t * random, uint32_t seed) {
+ int i;
random->status[0] = seed;
random->status[1] = random->mat1;
random->status[2] = random->mat2;
random->status[3] = random->tmat;
- for (int i = 1; i < MIN_LOOP; i++) {
+ for (i = 1; i < MIN_LOOP; i++) {
random->status[i & 3] ^= i + UINT32_C(1812433253)
* (random->status[(i - 1) & 3]
^ (random->status[(i - 1) & 3] >> 30));
}
period_certification(random);
- for (int i = 0; i < PRE_LOOP; i++) {
+ for (i = 0; i < PRE_LOOP; i++) {
tinymt32_next_state(random);
}
}
diff -urN tinymt.orig\tinymt32.h tinymt\tinymt32.h
--- tinymt.orig\tinymt32.h Fri Jun 29 12:11:18 2012
+++ tinymt\tinymt32.h Fri Jun 29 12:11:18 2012
@@ -16,8 +16,17 @@
* LICENSE.txt
*/
-#include <stdint.h>
-#include <inttypes.h>
+#include "hbapi.h"
+
+#if defined( __BORLANDC__ )
+# pragma warn -inl
+#endif
+
+#if ! defined( UINT32_C )
+# define UINT32_C( val ) ( val##U )
+#endif
+#define uint32_t HB_U32
+#define int32_t HB_I32
#define TINYMT32_MEXP 127
#define TINYMT32_SH0 1
@@ -48,12 +57,12 @@
* @param random not used
* @return always 127
*/
-inline static int tinymt32_get_mexp(
+_HB_INLINE_ static int tinymt32_get_mexp(
tinymt32_t * random __attribute__((unused))) {
return TINYMT32_MEXP;
}
#else
-inline static int tinymt32_get_mexp(tinymt32_t * random) {
+_HB_INLINE_ static int tinymt32_get_mexp(tinymt32_t * random) {
return TINYMT32_MEXP;
}
#endif
@@ -63,7 +72,7 @@
* Users should not call this function directly.
* @param random tinymt internal status
*/
-inline static void tinymt32_next_state(tinymt32_t * random) {
+_HB_INLINE_ static void tinymt32_next_state(tinymt32_t * random) {
uint32_t x;
uint32_t y;
@@ -87,7 +96,7 @@
* @param random tinymt internal status
* @return 32-bit unsigned pseudorandom number
*/
-inline static uint32_t tinymt32_temper(tinymt32_t * random) {
+_HB_INLINE_ static uint32_t tinymt32_temper(tinymt32_t * random) {
uint32_t t0, t1;
t0 = random->status[3];
#if defined(LINEARITY_CHECK)
@@ -108,7 +117,7 @@
* @param random tinymt internal status
* @return floating point number r (1.0 <= r < 2.0)
*/
-inline static float tinymt32_temper_conv(tinymt32_t * random) {
+_HB_INLINE_ static float tinymt32_temper_conv(tinymt32_t * random) {
uint32_t t0, t1;
union {
uint32_t u;
@@ -135,7 +144,7 @@
* @param random tinymt internal status
* @return floating point number r (1.0 < r < 2.0)
*/
-inline static float tinymt32_temper_conv_open(tinymt32_t * random) {
+_HB_INLINE_ static float tinymt32_temper_conv_open(tinymt32_t * random) {
uint32_t t0, t1;
union {
uint32_t u;
@@ -161,7 +170,7 @@
* @param random tinymt internal status
* @return 32-bit unsigned integer r (0 <= r < 2^32)
*/
-inline static uint32_t tinymt32_generate_uint32(tinymt32_t * random) {
+_HB_INLINE_ static uint32_t tinymt32_generate_uint32(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper(random);
}
@@ -174,7 +183,7 @@
* @param random tinymt internal status
* @return floating point number r (0.0 <= r < 1.0)
*/
-inline static float tinymt32_generate_float(tinymt32_t * random) {
+_HB_INLINE_ static float tinymt32_generate_float(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper(random) * TINYMT32_MUL;
}
@@ -185,7 +194,7 @@
* @param random tinymt internal status
* @return floating point number r (1.0 <= r < 2.0)
*/
-inline static float tinymt32_generate_float12(tinymt32_t * random) {
+_HB_INLINE_ static float tinymt32_generate_float12(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper_conv(random);
}
@@ -196,7 +205,7 @@
* @param random tinymt internal status
* @return floating point number r (0.0 <= r < 1.0)
*/
-inline static float tinymt32_generate_float01(tinymt32_t * random) {
+_HB_INLINE_ static float tinymt32_generate_float01(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper_conv(random) - 1.0f;
}
@@ -207,7 +216,7 @@
* @param random tinymt internal status
* @return floating point number r (0.0 < r <= 1.0)
*/
-inline static float tinymt32_generate_floatOC(tinymt32_t * random) {
+_HB_INLINE_ static float tinymt32_generate_floatOC(tinymt32_t * random) {
tinymt32_next_state(random);
return 1.0f - tinymt32_generate_float(random);
}
@@ -218,7 +227,7 @@
* @param random tinymt internal status
* @return floating point number r (0.0 < r < 0.0)
*/
-inline static float tinymt32_generate_floatOO(tinymt32_t * random) {
+_HB_INLINE_ static float tinymt32_generate_floatOO(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper_conv_open(random) - 1.0f;
}
@@ -231,7 +240,7 @@
* @param random tinymt internal status
* @return floating point number r (1.0 < r < 2.0)
*/
-inline static double tinymt32_generate_32double(tinymt32_t * random) {
+_HB_INLINE_ static double tinymt32_generate_32double(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper(random) * (1.0 / 4294967296.0);
}
diff -urN tinymt.orig\tinymt64.c tinymt\tinymt64.c
--- tinymt.orig\tinymt64.c Fri Jun 29 12:11:18 2012
+++ tinymt\tinymt64.c Fri Jun 29 12:11:18 2012
@@ -56,9 +56,10 @@
* @param seed a 64-bit unsigned integer used as a seed.
*/
void tinymt64_init(tinymt64_t * random, uint64_t seed) {
+ int i;
random->status[0] = seed ^ ((uint64_t)random->mat1 << 32);
random->status[1] = random->mat2 ^ random->tmat;
- for (int i = 1; i < MIN_LOOP; i++) {
+ for (i = 1; i < MIN_LOOP; i++) {
random->status[i & 1] ^= i + UINT64_C(6364136223846793005)
* (random->status[(i - 1) & 1]
^ (random->status[(i - 1) & 1] >> 62));
diff -urN tinymt.orig\tinymt64.h tinymt\tinymt64.h
--- tinymt.orig\tinymt64.h Fri Jun 29 12:11:18 2012
+++ tinymt\tinymt64.h Fri Jun 29 12:11:18 2012
@@ -16,8 +16,23 @@
* LICENSE.txt
*/
-#include <stdint.h>
-#include <inttypes.h>
+#include "hbapi.h"
+
+#if defined( __BORLANDC__ )
+# pragma warn -inl
+#endif
+
+#if ! defined( UINT32_C )
+# define UINT32_C( val ) ( val##U )
+#endif
+#define uint32_t HB_U32
+#define int32_t HB_I32
+
+#if ! defined( UINT64_C )
+# define UINT64_C( val ) HB_ULL( val )
+#endif
+#define uint64_t HB_U64
+#define int64_t HB_I64
#define TINYMT64_MEXP 127
#define TINYMT64_SH0 12
@@ -48,12 +63,12 @@
* @param random not used
* @return always 127
*/
-inline static int tinymt64_get_mexp(
+_HB_INLINE_ static int tinymt64_get_mexp(
tinymt64_t * random __attribute__((unused))) {
return TINYMT64_MEXP;
}
#else
-inline static int tinymt64_get_mexp(tinymt64_t * random) {
+_HB_INLINE_ static int tinymt64_get_mexp(tinymt64_t * random) {
return TINYMT64_MEXP;
}
#endif
@@ -63,7 +78,7 @@
* Users should not call this function directly.
* @param random tinymt internal status
*/
-inline static void tinymt64_next_state(tinymt64_t * random) {
+_HB_INLINE_ static void tinymt64_next_state(tinymt64_t * random) {
uint64_t x;
random->status[0] &= TINYMT64_MASK;
@@ -84,7 +99,7 @@
* @param random tinymt internal status
* @return 64-bit unsigned pseudorandom number
*/
-inline static uint64_t tinymt64_temper(tinymt64_t * random) {
+_HB_INLINE_ static uint64_t tinymt64_temper(tinymt64_t * random) {
uint64_t x;
#if defined(LINEARITY_CHECK)
x = random->status[0] ^ random->status[1];
@@ -102,7 +117,7 @@
* @param random tinymt internal status
* @return floating point number r (1.0 <= r < 2.0)
*/
-inline static double tinymt64_temper_conv(tinymt64_t * random) {
+_HB_INLINE_ static double tinymt64_temper_conv(tinymt64_t * random) {
uint64_t x;
union {
uint64_t u;
@@ -125,7 +140,7 @@
* @param random tinymt internal status
* @return floating point number r (1.0 < r < 2.0)
*/
-inline static double tinymt64_temper_conv_open(tinymt64_t * random) {
+_HB_INLINE_ static double tinymt64_temper_conv_open(tinymt64_t * random) {
uint64_t x;
union {
uint64_t u;
@@ -147,7 +162,7 @@
* @param random tinymt internal status
* @return 64-bit unsigned integer r (0 <= r < 2^64)
*/
-inline static uint64_t tinymt64_generate_uint64(tinymt64_t * random) {
+_HB_INLINE_ static uint64_t tinymt64_generate_uint64(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper(random);
}
@@ -158,7 +173,7 @@
* @param random tinymt internal status
* @return floating point number r (0.0 <= r < 1.0)
*/
-inline static double tinymt64_generate_double(tinymt64_t * random) {
+_HB_INLINE_ static double tinymt64_generate_double(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper(random) * TINYMT64_MUL;
}
@@ -169,7 +184,7 @@
* @param random tinymt internal status
* @return floating point number r (0.0 <= r < 1.0)
*/
-inline static double tinymt64_generate_double01(tinymt64_t * random) {
+_HB_INLINE_ static double tinymt64_generate_double01(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper_conv(random) - 1.0;
}
@@ -180,7 +195,7 @@
* @param random tinymt internal status
* @return floating point number r (1.0 <= r < 2.0)
*/
-inline static double tinymt64_generate_double12(tinymt64_t * random) {
+_HB_INLINE_ static double tinymt64_generate_double12(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper_conv(random);
}
@@ -191,7 +206,7 @@
* @param random tinymt internal status
* @return floating point number r (0.0 < r <= 1.0)
*/
-inline static double tinymt64_generate_doubleOC(tinymt64_t * random) {
+_HB_INLINE_ static double tinymt64_generate_doubleOC(tinymt64_t * random) {
tinymt64_next_state(random);
return 2.0 - tinymt64_temper_conv(random);
}
@@ -202,7 +217,7 @@
* @param random tinymt internal status
* @return floating point number r (0.0 < r < 1.0)
*/
-inline static double tinymt64_generate_doubleOO(tinymt64_t * random) {
+_HB_INLINE_ static double tinymt64_generate_doubleOO(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper_conv_open(random) - 1.0;
}

View File

@@ -0,0 +1,5 @@
#
# $Id: expat.hbc 16154 2011-01-30 23:09:11Z vszakats $
#
libs=${hb_name}

View File

@@ -0,0 +1,27 @@
#
# $Id: expat.hbp 16466 2011-03-11 00:28:04Z vszakats $
#
-stop{hbdyn}
-hblib
-inc
-o${hb_targetname}
-warn=low
-pic
tinymt32.c
tinymt64.c
# ORIGIN http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/TINYMT/
# VER 1.0.1
# URL http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/TINYMT/TinyMT-src-1.0.1.zip
# DIFF tinymt.dif
#
# MAP LICENSE.txt LICENSE.txt
# MAP tinymt/tinymt32.c tinymt32.c
# MAP tinymt/tinymt64.c tinymt64.c
# MAP tinymt/tinymt32.h tinymt32.h
# MAP tinymt/tinymt64.h tinymt64.h

View File

@@ -0,0 +1,33 @@
/*
* $Id$
*/
/* -------------------------------------------------------------------- */
/* NOTE: You can add manual override which functions to include or */
/* exclude from automatically generated EXTERNAL/DYNAMIC list. */
/* Syntax: // HB_FUNC_INCLUDE <func> */
/* // HB_FUNC_EXCLUDE <func> */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* WARNING: Automatically generated code below. DO NOT EDIT! */
/* Regenerate using hbmk2 '-hbx=' option. */
/* -------------------------------------------------------------------- */
#ifndef __HBEXTERN_CH__TINYMT__
#define __HBEXTERN_CH__TINYMT__
#if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__TINYMT__ANNOUNCE )
ANNOUNCE __HBEXTERN__TINYMT__
#endif
#if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__TINYMT__REQUEST )
#command DYNAMIC <fncs,...> => EXTERNAL <fncs>
#endif
#if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__TINYMT__REQUEST )
#uncommand DYNAMIC <fncs,...> => EXTERNAL <fncs>
#endif
#endif

View File

@@ -0,0 +1,140 @@
/**
* @file tinymt32.c
*
* @brief Tiny Mersenne Twister only 127 bit internal state
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (The University of Tokyo)
*
* Copyright (C) 2011 Mutsuo Saito, Makoto Matsumoto,
* Hiroshima University and The University of Tokyo.
* All rights reserved.
*
* The 3-clause BSD License is applied to this software, see
* LICENSE.txt
*/
#include "tinymt32.h"
#define MIN_LOOP 8
#define PRE_LOOP 8
/**
* This function represents a function used in the initialization
* by init_by_array
* @param x 32-bit integer
* @return 32-bit integer
*/
static uint32_t ini_func1(uint32_t x) {
return (x ^ (x >> 27)) * (uint32_t)1664525UL;
}
/**
* This function represents a function used in the initialization
* by init_by_array
* @param x 32-bit integer
* @return 32-bit integer
*/
static uint32_t ini_func2(uint32_t x) {
return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
}
/**
* This function certificate the period of 2^127-1.
* @param random tinymt state vector.
*/
static void period_certification(tinymt32_t * random) {
if ((random->status[0] & TINYMT32_MASK) == 0 &&
random->status[1] == 0 &&
random->status[2] == 0 &&
random->status[3] == 0) {
random->status[0] = 'T';
random->status[1] = 'I';
random->status[2] = 'N';
random->status[3] = 'Y';
}
}
/**
* This function initializes the internal state array with a 32-bit
* unsigned integer seed.
* @param random tinymt state vector.
* @param seed a 32-bit unsigned integer used as a seed.
*/
void tinymt32_init(tinymt32_t * random, uint32_t seed) {
int i;
random->status[0] = seed;
random->status[1] = random->mat1;
random->status[2] = random->mat2;
random->status[3] = random->tmat;
for (i = 1; i < MIN_LOOP; i++) {
random->status[i & 3] ^= i + UINT32_C(1812433253)
* (random->status[(i - 1) & 3]
^ (random->status[(i - 1) & 3] >> 30));
}
period_certification(random);
for (i = 0; i < PRE_LOOP; i++) {
tinymt32_next_state(random);
}
}
/**
* This function initializes the internal state array,
* with an array of 32-bit unsigned integers used as seeds
* @param random tinymt state vector.
* @param init_key the array of 32-bit integers, used as a seed.
* @param key_length the length of init_key.
*/
void tinymt32_init_by_array(tinymt32_t * random, uint32_t init_key[],
int key_length) {
const int lag = 1;
const int mid = 1;
const int size = 4;
int i, j;
int count;
uint32_t r;
uint32_t * st = &random->status[0];
st[0] = 0;
st[1] = random->mat1;
st[2] = random->mat2;
st[3] = random->tmat;
if (key_length + 1 > MIN_LOOP) {
count = key_length + 1;
} else {
count = MIN_LOOP;
}
r = ini_func1(st[0] ^ st[mid % size]
^ st[(size - 1) % size]);
st[mid % size] += r;
r += key_length;
st[(mid + lag) % size] += r;
st[0] = r;
count--;
for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
st[(i + mid) % size] += r;
r += init_key[j] + i;
st[(i + mid + lag) % size] += r;
st[i] = r;
i = (i + 1) % size;
}
for (; j < count; j++) {
r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
st[(i + mid) % size] += r;
r += i;
st[(i + mid + lag) % size] += r;
st[i] = r;
i = (i + 1) % size;
}
for (j = 0; j < size; j++) {
r = ini_func2(st[i] + st[(i + mid) % size] + st[(i + size - 1) % size]);
st[(i + mid) % size] ^= r;
r -= i;
st[(i + mid + lag) % size] ^= r;
st[i] = r;
i = (i + 1) % size;
}
period_certification(random);
for (i = 0; i < PRE_LOOP; i++) {
tinymt32_next_state(random);
}
}

View File

@@ -0,0 +1,247 @@
#ifndef TINYMT32_H
#define TINYMT32_H
/**
* @file tinymt32.h
*
* @brief Tiny Mersenne Twister only 127 bit internal state
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (University of Tokyo)
*
* Copyright (C) 2011 Mutsuo Saito, Makoto Matsumoto,
* Hiroshima University and The University of Tokyo.
* All rights reserved.
*
* The 3-clause BSD License is applied to this software, see
* LICENSE.txt
*/
#include "hbapi.h"
#if defined( __BORLANDC__ )
# pragma warn -inl
#endif
#if ! defined( UINT32_C )
# define UINT32_C( val ) ( val##U )
#endif
#define uint32_t HB_U32
#define int32_t HB_I32
#define TINYMT32_MEXP 127
#define TINYMT32_SH0 1
#define TINYMT32_SH1 10
#define TINYMT32_SH8 8
#define TINYMT32_MASK UINT32_C(0x7fffffff)
#define TINYMT32_MUL (1.0f / 4294967296.0f)
/**
* tinymt32 internal state vector and parameters
*/
struct TINYMT32_T {
uint32_t status[4];
uint32_t mat1;
uint32_t mat2;
uint32_t tmat;
};
typedef struct TINYMT32_T tinymt32_t;
void tinymt32_init(tinymt32_t * random, uint32_t seed);
void tinymt32_init_by_array(tinymt32_t * random, uint32_t init_key[],
int key_length);
#if defined(__GNUC__)
/**
* This function always returns 127
* @param random not used
* @return always 127
*/
_HB_INLINE_ static int tinymt32_get_mexp(
tinymt32_t * random __attribute__((unused))) {
return TINYMT32_MEXP;
}
#else
_HB_INLINE_ static int tinymt32_get_mexp(tinymt32_t * random) {
return TINYMT32_MEXP;
}
#endif
/**
* This function changes internal state of tinymt32.
* Users should not call this function directly.
* @param random tinymt internal status
*/
_HB_INLINE_ static void tinymt32_next_state(tinymt32_t * random) {
uint32_t x;
uint32_t y;
y = random->status[3];
x = (random->status[0] & TINYMT32_MASK)
^ random->status[1]
^ random->status[2];
x ^= (x << TINYMT32_SH0);
y ^= (y >> TINYMT32_SH0) ^ x;
random->status[0] = random->status[1];
random->status[1] = random->status[2];
random->status[2] = x ^ (y << TINYMT32_SH1);
random->status[3] = y;
random->status[1] ^= -((int32_t)(y & 1)) & random->mat1;
random->status[2] ^= -((int32_t)(y & 1)) & random->mat2;
}
/**
* This function outputs 32-bit unsigned integer from internal state.
* Users should not call this function directly.
* @param random tinymt internal status
* @return 32-bit unsigned pseudorandom number
*/
_HB_INLINE_ static uint32_t tinymt32_temper(tinymt32_t * random) {
uint32_t t0, t1;
t0 = random->status[3];
#if defined(LINEARITY_CHECK)
t1 = random->status[0]
^ (random->status[2] >> TINYMT32_SH8);
#else
t1 = random->status[0]
+ (random->status[2] >> TINYMT32_SH8);
#endif
t0 ^= t1;
t0 ^= -((int32_t)(t1 & 1)) & random->tmat;
return t0;
}
/**
* This function outputs floating point number from internal state.
* Users should not call this function directly.
* @param random tinymt internal status
* @return floating point number r (1.0 <= r < 2.0)
*/
_HB_INLINE_ static float tinymt32_temper_conv(tinymt32_t * random) {
uint32_t t0, t1;
union {
uint32_t u;
float f;
} conv;
t0 = random->status[3];
#if defined(LINEARITY_CHECK)
t1 = random->status[0]
^ (random->status[2] >> TINYMT32_SH8);
#else
t1 = random->status[0]
+ (random->status[2] >> TINYMT32_SH8);
#endif
t0 ^= t1;
conv.u = ((t0 ^ (-((int32_t)(t1 & 1)) & random->tmat)) >> 9)
| UINT32_C(0x3f800000);
return conv.f;
}
/**
* This function outputs floating point number from internal state.
* Users should not call this function directly.
* @param random tinymt internal status
* @return floating point number r (1.0 < r < 2.0)
*/
_HB_INLINE_ static float tinymt32_temper_conv_open(tinymt32_t * random) {
uint32_t t0, t1;
union {
uint32_t u;
float f;
} conv;
t0 = random->status[3];
#if defined(LINEARITY_CHECK)
t1 = random->status[0]
^ (random->status[2] >> TINYMT32_SH8);
#else
t1 = random->status[0]
+ (random->status[2] >> TINYMT32_SH8);
#endif
t0 ^= t1;
conv.u = ((t0 ^ (-((int32_t)(t1 & 1)) & random->tmat)) >> 9)
| UINT32_C(0x3f800001);
return conv.f;
}
/**
* This function outputs 32-bit unsigned integer from internal state.
* @param random tinymt internal status
* @return 32-bit unsigned integer r (0 <= r < 2^32)
*/
_HB_INLINE_ static uint32_t tinymt32_generate_uint32(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper(random);
}
/**
* This function outputs floating point number from internal state.
* This function is implemented using multiplying by 1 / 2^32.
* floating point multiplication is faster than using union trick in
* my Intel CPU.
* @param random tinymt internal status
* @return floating point number r (0.0 <= r < 1.0)
*/
_HB_INLINE_ static float tinymt32_generate_float(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper(random) * TINYMT32_MUL;
}
/**
* This function outputs floating point number from internal state.
* This function is implemented using union trick.
* @param random tinymt internal status
* @return floating point number r (1.0 <= r < 2.0)
*/
_HB_INLINE_ static float tinymt32_generate_float12(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper_conv(random);
}
/**
* This function outputs floating point number from internal state.
* This function is implemented using union trick.
* @param random tinymt internal status
* @return floating point number r (0.0 <= r < 1.0)
*/
_HB_INLINE_ static float tinymt32_generate_float01(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper_conv(random) - 1.0f;
}
/**
* This function outputs floating point number from internal state.
* This function may return 1.0 and never returns 0.0.
* @param random tinymt internal status
* @return floating point number r (0.0 < r <= 1.0)
*/
_HB_INLINE_ static float tinymt32_generate_floatOC(tinymt32_t * random) {
tinymt32_next_state(random);
return 1.0f - tinymt32_generate_float(random);
}
/**
* This function outputs floating point number from internal state.
* This function returns neither 0.0 nor 1.0.
* @param random tinymt internal status
* @return floating point number r (0.0 < r < 0.0)
*/
_HB_INLINE_ static float tinymt32_generate_floatOO(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper_conv_open(random) - 1.0f;
}
/**
* This function outputs double precision floating point number from
* internal state. The returned value has 32-bit precision.
* In other words, this function makes one double precision floating point
* number from one 32-bit unsigned integer.
* @param random tinymt internal status
* @return floating point number r (1.0 < r < 2.0)
*/
_HB_INLINE_ static double tinymt32_generate_32double(tinymt32_t * random) {
tinymt32_next_state(random);
return tinymt32_temper(random) * (1.0 / 4294967296.0);
}
#endif

View File

@@ -0,0 +1,130 @@
/**
* @file tinymt64.c
*
* @brief 64-bit Tiny Mersenne Twister only 127 bit internal state
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (The University of Tokyo)
*
* Copyright (C) 2011 Mutsuo Saito, Makoto Matsumoto,
* Hiroshima University and The University of Tokyo.
* All rights reserved.
*
* The 3-clause BSD License is applied to this software, see
* LICENSE.txt
*/
#include "tinymt64.h"
#define MIN_LOOP 8
/**
* This function represents a function used in the initialization
* by init_by_array
* @param[in] x 64-bit integer
* @return 64-bit integer
*/
static uint64_t ini_func1(uint64_t x) {
return (x ^ (x >> 59)) * UINT64_C(2173292883993);
}
/**
* This function represents a function used in the initialization
* by init_by_array
* @param[in] x 64-bit integer
* @return 64-bit integer
*/
static uint64_t ini_func2(uint64_t x) {
return (x ^ (x >> 59)) * UINT64_C(58885565329898161);
}
/**
* This function certificate the period of 2^127-1.
* @param random tinymt state vector.
*/
static void period_certification(tinymt64_t * random) {
if ((random->status[0] & TINYMT64_MASK) == 0 &&
random->status[1] == 0) {
random->status[0] = 'T';
random->status[1] = 'M';
}
}
/**
* This function initializes the internal state array with a 64-bit
* unsigned integer seed.
* @param random tinymt state vector.
* @param seed a 64-bit unsigned integer used as a seed.
*/
void tinymt64_init(tinymt64_t * random, uint64_t seed) {
int i;
random->status[0] = seed ^ ((uint64_t)random->mat1 << 32);
random->status[1] = random->mat2 ^ random->tmat;
for (i = 1; i < MIN_LOOP; i++) {
random->status[i & 1] ^= i + UINT64_C(6364136223846793005)
* (random->status[(i - 1) & 1]
^ (random->status[(i - 1) & 1] >> 62));
}
period_certification(random);
}
/**
* This function initializes the internal state array,
* with an array of 64-bit unsigned integers used as seeds
* @param random tinymt state vector.
* @param init_key the array of 64-bit integers, used as a seed.
* @param key_length the length of init_key.
*/
void tinymt64_init_by_array(tinymt64_t * random, const uint64_t init_key[],
int key_length) {
const int lag = 1;
const int mid = 1;
const int size = 4;
int i, j;
int count;
uint64_t r;
uint64_t st[4];
st[0] = 0;
st[1] = random->mat1;
st[2] = random->mat2;
st[3] = random->tmat;
if (key_length + 1 > MIN_LOOP) {
count = key_length + 1;
} else {
count = MIN_LOOP;
}
r = ini_func1(st[0] ^ st[mid % size]
^ st[(size - 1) % size]);
st[mid % size] += r;
r += key_length;
st[(mid + lag) % size] += r;
st[0] = r;
count--;
for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
st[(i + mid) % size] += r;
r += init_key[j] + i;
st[(i + mid + lag) % size] += r;
st[i] = r;
i = (i + 1) % size;
}
for (; j < count; j++) {
r = ini_func1(st[i] ^ st[(i + mid) % size] ^ st[(i + size - 1) % size]);
st[(i + mid) % size] += r;
r += i;
st[(i + mid + lag) % size] += r;
st[i] = r;
i = (i + 1) % size;
}
for (j = 0; j < size; j++) {
r = ini_func2(st[i] + st[(i + mid) % size] + st[(i + size - 1) % size]);
st[(i + mid) % size] ^= r;
r -= i;
st[(i + mid + lag) % size] ^= r;
st[i] = r;
i = (i + 1) % size;
}
random->status[0] = st[0] ^ st[1];
random->status[1] = st[2] ^ st[3];
period_certification(random);
}

View File

@@ -0,0 +1,225 @@
#ifndef TINYMT64_H
#define TINYMT64_H
/**
* @file tinymt64.h
*
* @brief Tiny Mersenne Twister only 127 bit internal state
*
* @author Mutsuo Saito (Hiroshima University)
* @author Makoto Matsumoto (The University of Tokyo)
*
* Copyright (C) 2011 Mutsuo Saito, Makoto Matsumoto,
* Hiroshima University and The University of Tokyo.
* All rights reserved.
*
* The 3-clause BSD License is applied to this software, see
* LICENSE.txt
*/
#include "hbapi.h"
#if defined( __BORLANDC__ )
# pragma warn -inl
#endif
#if ! defined( UINT32_C )
# define UINT32_C( val ) ( val##U )
#endif
#define uint32_t HB_U32
#define int32_t HB_I32
#if ! defined( UINT64_C )
# define UINT64_C( val ) HB_ULL( val )
#endif
#define uint64_t HB_U64
#define int64_t HB_I64
#define TINYMT64_MEXP 127
#define TINYMT64_SH0 12
#define TINYMT64_SH1 11
#define TINYMT64_SH8 8
#define TINYMT64_MASK UINT64_C(0x7fffffffffffffff)
#define TINYMT64_MUL (1.0 / 18446744073709551616.0)
/*
* tinymt64 internal state vector and parameters
*/
struct TINYMT64_T {
uint64_t status[2];
uint32_t mat1;
uint32_t mat2;
uint64_t tmat;
};
typedef struct TINYMT64_T tinymt64_t;
void tinymt64_init(tinymt64_t * random, uint64_t seed);
void tinymt64_init_by_array(tinymt64_t * random, const uint64_t init_key[],
int key_length);
#if defined(__GNUC__)
/**
* This function always returns 127
* @param random not used
* @return always 127
*/
_HB_INLINE_ static int tinymt64_get_mexp(
tinymt64_t * random __attribute__((unused))) {
return TINYMT64_MEXP;
}
#else
_HB_INLINE_ static int tinymt64_get_mexp(tinymt64_t * random) {
return TINYMT64_MEXP;
}
#endif
/**
* This function changes internal state of tinymt64.
* Users should not call this function directly.
* @param random tinymt internal status
*/
_HB_INLINE_ static void tinymt64_next_state(tinymt64_t * random) {
uint64_t x;
random->status[0] &= TINYMT64_MASK;
x = random->status[0] ^ random->status[1];
x ^= x << TINYMT64_SH0;
x ^= x >> 32;
x ^= x << 32;
x ^= x << TINYMT64_SH1;
random->status[0] = random->status[1];
random->status[1] = x;
random->status[0] ^= -((int64_t)(x & 1)) & random->mat1;
random->status[1] ^= -((int64_t)(x & 1)) & (((uint64_t)random->mat2) << 32);
}
/**
* This function outputs 64-bit unsigned integer from internal state.
* Users should not call this function directly.
* @param random tinymt internal status
* @return 64-bit unsigned pseudorandom number
*/
_HB_INLINE_ static uint64_t tinymt64_temper(tinymt64_t * random) {
uint64_t x;
#if defined(LINEARITY_CHECK)
x = random->status[0] ^ random->status[1];
#else
x = random->status[0] + random->status[1];
#endif
x ^= random->status[0] >> TINYMT64_SH8;
x ^= -((int64_t)(x & 1)) & random->tmat;
return x;
}
/**
* This function outputs floating point number from internal state.
* Users should not call this function directly.
* @param random tinymt internal status
* @return floating point number r (1.0 <= r < 2.0)
*/
_HB_INLINE_ static double tinymt64_temper_conv(tinymt64_t * random) {
uint64_t x;
union {
uint64_t u;
double d;
} conv;
#if defined(LINEARITY_CHECK)
x = random->status[0] ^ random->status[1];
#else
x = random->status[0] + random->status[1];
#endif
x ^= random->status[0] >> TINYMT64_SH8;
conv.u = ((x ^ (-((int64_t)(x & 1)) & random->tmat)) >> 12)
| UINT64_C(0x3ff0000000000000);
return conv.d;
}
/**
* This function outputs floating point number from internal state.
* Users should not call this function directly.
* @param random tinymt internal status
* @return floating point number r (1.0 < r < 2.0)
*/
_HB_INLINE_ static double tinymt64_temper_conv_open(tinymt64_t * random) {
uint64_t x;
union {
uint64_t u;
double d;
} conv;
#if defined(LINEARITY_CHECK)
x = random->status[0] ^ random->status[1];
#else
x = random->status[0] + random->status[1];
#endif
x ^= random->status[0] >> TINYMT64_SH8;
conv.u = ((x ^ (-((int64_t)(x & 1)) & random->tmat)) >> 12)
| UINT64_C(0x3ff0000000000001);
return conv.d;
}
/**
* This function outputs 64-bit unsigned integer from internal state.
* @param random tinymt internal status
* @return 64-bit unsigned integer r (0 <= r < 2^64)
*/
_HB_INLINE_ static uint64_t tinymt64_generate_uint64(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper(random);
}
/**
* This function outputs floating point number from internal state.
* This function is implemented using multiplying by 1 / 2^64.
* @param random tinymt internal status
* @return floating point number r (0.0 <= r < 1.0)
*/
_HB_INLINE_ static double tinymt64_generate_double(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper(random) * TINYMT64_MUL;
}
/**
* This function outputs floating point number from internal state.
* This function is implemented using union trick.
* @param random tinymt internal status
* @return floating point number r (0.0 <= r < 1.0)
*/
_HB_INLINE_ static double tinymt64_generate_double01(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper_conv(random) - 1.0;
}
/**
* This function outputs floating point number from internal state.
* This function is implemented using union trick.
* @param random tinymt internal status
* @return floating point number r (1.0 <= r < 2.0)
*/
_HB_INLINE_ static double tinymt64_generate_double12(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper_conv(random);
}
/**
* This function outputs floating point number from internal state.
* This function is implemented using union trick.
* @param random tinymt internal status
* @return floating point number r (0.0 < r <= 1.0)
*/
_HB_INLINE_ static double tinymt64_generate_doubleOC(tinymt64_t * random) {
tinymt64_next_state(random);
return 2.0 - tinymt64_temper_conv(random);
}
/**
* This function outputs floating point number from internal state.
* This function is implemented using union trick.
* @param random tinymt internal status
* @return floating point number r (0.0 < r < 1.0)
*/
_HB_INLINE_ static double tinymt64_generate_doubleOO(tinymt64_t * random) {
tinymt64_next_state(random);
return tinymt64_temper_conv_open(random) - 1.0;
}
#endif

View File

@@ -0,0 +1,158 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Harbour interface to TinyMT, Pseudo Random Generator
*
* Copyright 2012 Andi Jahja <xharbour@telkom.net.id>
* www - http://www.harbour-project.org http://www.xharbour.org
*
* This program 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, or (at your option)
* any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#include "hbapi.h"
#include "hbstack.h"
#include "tinymt32.h"
typedef struct
{
tinymt32_t tinymt;
} HB_TINYMTDATA, * PHB_TINYMTDATA;
static HB_TSD_NEW( s_tinymtData, sizeof( HB_TINYMTDATA ), NULL, NULL );
/* Syntax: HB_TINYMT32_INIT( <nVector1>, <nVector2>, <nVector3>, [<nSeed>] ) -> <lSuccess> */
HB_FUNC( HB_TINYMT32_INIT )
{
if( hb_pcount() >= 3 && HB_ISNUM( 1 ) && HB_ISNUM( 3 ) && HB_ISNUM( 3 ) )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
HB_U32 seed = ( HB_U32 ) hb_parnldef( 4, 1 );
tinymtData->tinymt.mat1 = hb_parnl( 1 );
tinymtData->tinymt.mat2 = hb_parnl( 2 );
tinymtData->tinymt.tmat = hb_parnl( 3 );
tinymt32_init( &tinymtData->tinymt, seed );
hb_retl( HB_TRUE );
}
else
hb_retl( HB_FALSE );
}
/* Syntax: HB_TINYMT32_INIT_BY_ARRAY( { <nVector1>, <nVector2>, <nVector3> }, [<nSeed>], [<nKeyLength>] ) -> <lSuccess> */
HB_FUNC( HB_TINYMT32_INIT_BY_ARRAY )
{
PHB_ITEM pArray = hb_param( 1, HB_IT_ARRAY );
if( pArray && hb_arrayLen( pArray ) == 3 )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
HB_U32 seed_array[ 5 ];
seed_array[ 0 ] = ( HB_U32 ) hb_parnldef( 2, 1 );
tinymtData->tinymt.mat1 = hb_arrayGetNL( pArray, 1 );
tinymtData->tinymt.mat2 = hb_arrayGetNL( pArray, 2 );
tinymtData->tinymt.tmat = hb_arrayGetNL( pArray, 3 );
tinymt32_init_by_array( &tinymtData->tinymt, seed_array, hb_parnldef( 3, 1 ) );
hb_retl( HB_TRUE );
}
else
hb_retl( HB_FALSE );
}
HB_FUNC( HB_TINYMT32_GENERATE_UINT32 )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
hb_retnint( tinymt32_generate_uint32( &tinymtData->tinymt ) );
}
HB_FUNC( HB_TINYMT32_GENERATE_FLOAT )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
hb_retnd( tinymt32_generate_float( &tinymtData->tinymt ) );
}
HB_FUNC( HB_TINYMT32_GENERATE_FLOAT01 )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
hb_retnd( tinymt32_generate_float01( &tinymtData->tinymt ) );
}
HB_FUNC( HB_TINYMT32_GENERATE_FLOAT12 )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
hb_retnd( tinymt32_generate_float12( &tinymtData->tinymt ) );
}
HB_FUNC( HB_TINYMT32_GENERATE_FLOATOC )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
hb_retnd( tinymt32_generate_floatOC( &tinymtData->tinymt ) );
}
HB_FUNC( HB_TINYMT32_GENERATE_FLOATOO )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
hb_retnd( tinymt32_generate_floatOO( &tinymtData->tinymt ) );
}
HB_FUNC( HB_TINYMT32_GENERATE_32DOUBLE )
{
PHB_TINYMTDATA tinymtData = ( PHB_TINYMTDATA ) hb_stackGetTSD( &s_tinymtData );
hb_retnd( tinymt32_generate_32double( &tinymtData->tinymt ) );
}

View File

@@ -0,0 +1,8 @@
#
# $Id$
#
incpaths=.
libs=${_HB_DYNPREF}${hb_name}${_HB_DYNSUFF}
libs=3rd/tinymt/tinymt.hbc

View File

@@ -0,0 +1,26 @@
#
# $Id$
#
#-stop{win&!allgcc&!watcom}
-hblib
-inc
-o${hb_targetname}
-w3 -es2
-depkeyhead=tinymt:tinymt32.h
-depcontrol=tinymt:local{HB_BUILD_3RDEXT='no'}
-depcontrol=tinymt:${HB_WITH_TINYMT}
-depincpath=tinymt:/usr/include
-depincpathlocal=tinymt:3rd/tinymt
-depfinish=tinymt
hbtinymt.hbx
core32.c
core64.c
3rd/tinymt/tinymt.hbc{HBMK_HAS_TINYMT_LOCAL}

View File

@@ -0,0 +1,50 @@
/*
* $Id$
*/
/* -------------------------------------------------------------------- */
/* NOTE: You can add manual override which functions to include or */
/* exclude from automatically generated EXTERNAL/DYNAMIC list. */
/* Syntax: // HB_FUNC_INCLUDE <func> */
/* // HB_FUNC_EXCLUDE <func> */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* WARNING: Automatically generated code below. DO NOT EDIT! */
/* Regenerate using hbmk2 '-hbx=' option. */
/* -------------------------------------------------------------------- */
#ifndef __HBEXTERN_CH__HBTINYMT__
#define __HBEXTERN_CH__HBTINYMT__
#if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__HBTINYMT__ANNOUNCE )
ANNOUNCE __HBEXTERN__HBTINYMT__
#endif
#if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__HBTINYMT__REQUEST )
#command DYNAMIC <fncs,...> => EXTERNAL <fncs>
#endif
DYNAMIC hb_tinymt32_generate_32double
DYNAMIC hb_tinymt32_generate_float
DYNAMIC hb_tinymt32_generate_float01
DYNAMIC hb_tinymt32_generate_float12
DYNAMIC hb_tinymt32_generate_floatoc
DYNAMIC hb_tinymt32_generate_floatoo
DYNAMIC hb_tinymt32_generate_uint32
DYNAMIC hb_tinymt32_init
DYNAMIC hb_tinymt32_init_by_array
DYNAMIC hb_tinymt64_generate_double
DYNAMIC hb_tinymt64_generate_double01
DYNAMIC hb_tinymt64_generate_double12
DYNAMIC hb_tinymt64_generate_doubleoc
DYNAMIC hb_tinymt64_generate_doubleoo
DYNAMIC hb_tinymt64_generate_uint64
DYNAMIC hb_tinymt64_init
DYNAMIC hb_tinymt64_init_by_array
#if defined( __HBEXTREQ__ ) .OR. defined( __HBEXTERN__HBTINYMT__REQUEST )
#uncommand DYNAMIC <fncs,...> => EXTERNAL <fncs>
#endif
#endif

View File

@@ -0,0 +1,7 @@
#
# $Id$
#
hbtinymt.hbc
-w3 -es2

View File

@@ -0,0 +1,96 @@
/*
* $Id$
*/
/*
* Test program for HBTINYMT library
* Andi Jahja
*/
PROCEDURE Main()
LOCAL i, j
SET DECIMAL TO 0
IF hb_tinymt32_init( 0x123, 0x234, 0x345 )
OutStd( "32-bit unsigned integers r, where 0 <= r < 2^32" )
OutStd( hb_eol() )
FOR i := 1 TO 10
FOR j := 1 TO 5
OutStd( PadL( HB_TINYMT32_GENERATE_UINT32(), 11 ) )
NEXT
OutStd( hb_eol() )
NEXT
ENDIF
OutStd( hb_eol() )
SET DECIMAL TO 12
IF hb_tinymt32_init_by_array( { 0x123, 0x234, 0x345 } )
OutStd( "Float numbers r, where 0.0 <= r < 1.0" )
OutStd( hb_eol() )
FOR i := 1 TO 10
FOR j := 1 TO 5
OutStd( PadL( hb_tinymt32_generate_float(), 15 ) )
NEXT
OutStd( hb_eol() )
NEXT
OutStd( hb_eol() )
OutStd( hb_eol() )
OutStd( "Float numbers r, where 0.0 <= r < 1.0" )
OutStd( hb_eol() )
FOR i := 1 TO 10
FOR j := 1 TO 5
OutStd( PadL( hb_tinymt32_generate_float01(), 15 ) )
NEXT
OutStd( hb_eol() )
NEXT
OutStd( hb_eol() )
OutStd( hb_eol() )
OutStd( "Float numbers r, where 1.0 <= r < 2.0" )
OutStd( hb_eol() )
FOR i := 1 TO 10
FOR j := 1 TO 5
OutStd( PadL( hb_tinymt32_generate_float12(), 15 ) )
NEXT
OutStd( hb_eol() )
NEXT
OutStd( hb_eol() )
OutStd( hb_eol() )
OutStd( "Float numbers r, where 0.0 < r <= 1.0" )
OutStd( hb_eol() )
FOR i := 1 TO 10
FOR j := 1 TO 5
OutStd( PadL( hb_tinymt32_generate_floatoc(), 15 ) )
NEXT
OutStd( hb_eol() )
NEXT
OutStd( hb_eol() )
OutStd( hb_eol() )
OutStd( "Float numbers r, where 0.0 < r < 1.0" )
OutStd( hb_eol() )
FOR i := 1 TO 10
FOR j := 1 TO 5
OutStd( PadL( hb_tinymt32_generate_floatoo(), 15 ) )
NEXT
OutStd( hb_eol() )
NEXT
OutStd( hb_eol() )
OutStd( hb_eol() )
OutStd( "32-bit precision double numbers r, where 0.0 <= r < 1.0" )
OutStd( hb_eol() )
FOR i := 1 TO 10
FOR j := 1 TO 5
OutStd( PadL( hb_tinymt32_generate_32double(), 15 ) )
NEXT
OutStd( hb_eol() )
NEXT
ENDIF
RETURN