Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

zigrandom.h

Go to the documentation of this file.
00001 #ifndef INCLUDED_ZIGRANDOM_H
00002 #define INCLUDED_ZIGRANDOM_H
00003 
00004 /*! @file
00005 *==========================================================================
00006 *  This code is Copyright (C) 2005, Jurgen A. Doornik.
00007 *  Permission to use this code for non-commercial purposes
00008 *  is hereby given, provided proper reference is made to:
00009 *   Doornik, J.A. (2005), "An Improved Ziggurat Method to Generate Normal
00010 *          Random Samples", mimeo, Nuffield College, University of Oxford,
00011 *     and www.doornik.com/research.
00012 *   or the published version when available.
00013 * This reference is still required when using modified versions of the code.
00014 *  This notice should be maintained in modified versions of the code.
00015 * No warranty is given regarding the correctness of this code.
00016 *==========================================================================
00017 *
00018 * @author Jurgen A. Doornik (Creator)
00019 *
00020 * $Author: ejt $
00021 * $Name: tekkotsu-4_0 $
00022 * $Revision: 1.1 $
00023 * $State: Exp $
00024 * $Date: 2007/01/25 20:54:13 $
00025 */
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030   
00031 #ifdef __LP64__
00032   typedef unsigned long UINT64;
00033   typedef          long INT64;
00034   #define LIT_UINT64(c) (c##ul)
00035   #define LIT_INT64(c)  (c##l)
00036 #elif defined(_MSC_VER)
00037   typedef unsigned __int64 UINT64;
00038   typedef          __int64 INT64;
00039   #define LIT_UINT64(c) (c##ui64)
00040   #define LIT_INT64(c)  (c##i64)
00041 #else 
00042   typedef unsigned long long UINT64;
00043   typedef          long long INT64;
00044   #define LIT_UINT64(c) (c##ull)
00045   #define LIT_INT64(c)  (c##ll)
00046 #endif
00047 
00048 #define M_RAN_INVM30  9.31322574615478515625e-010       /* 1.0 / 2^30 */
00049 #define M_RAN_INVM32  2.32830643653869628906e-010       /* 1.0 / 2^32 */
00050 #define M_RAN_INVM48  3.55271367880050092936e-015       /* 1.0 / 2^48 */
00051 #define M_RAN_INVM52  2.22044604925031308085e-016       /* 1.0 / 2^52 */
00052 #define M_RAN_INVM64  5.42101086242752217004e-020       /* 1.0 / 2^64 */
00053 
00054 #define RANDBL_32old(iRan1)           \
00055     ((unsigned int)(iRan1) * M_RAN_INVM32)
00056 #define RANDBL_48old(iRan1, iRan2)      \
00057     ((unsigned int)(iRan1) + (unsigned int)((iRan2) << 16) \
00058     * M_RAN_INVM32) * M_RAN_INVM32
00059 #define RANDBL_52old(iRan1, iRan2)      \
00060     ((unsigned int)(iRan1) + (unsigned int)((iRan2) << 12) \
00061     * M_RAN_INVM32) * M_RAN_INVM32
00062 
00063 #define RANDBL_32new(iRan1)                   \
00064     ((int)(iRan1) * M_RAN_INVM32 + (0.5 + M_RAN_INVM32 / 2))
00065 #define RANDBL_48new(iRan1, iRan2)            \
00066     ((int)(iRan1) * M_RAN_INVM32 + (0.5 + M_RAN_INVM48 / 2) + \
00067         (int)((iRan2) & 0x0000FFFF) * M_RAN_INVM48)
00068 #define RANDBL_52new(iRan1, iRan2)            \
00069     ((int)(iRan1) * M_RAN_INVM32 + (0.5 + M_RAN_INVM52 / 2) + \
00070         (int)((iRan2) & 0x000FFFFF) * M_RAN_INVM52)
00071 
00072 void  GetInitialSeeds(unsigned int auiSeed[], int cSeed,
00073   unsigned int uiSeed, unsigned int uiMin);
00074 
00075 /* MWC8222 George Marsaglia */
00076 void RanSetSeed_MWC8222(int *piSeed, int cSeed);
00077 unsigned int IRan_MWC8222(void);
00078 double DRan_MWC8222(void);
00079 void VecIRan_MWC8222(unsigned int *auiRan, int cRan);
00080 void VecDRan_MWC8222(double *adRan, int cRan);
00081 
00082 /* plug-in RNG */
00083 typedef double    ( * DRANFUN)(void);
00084 typedef unsigned int( * IRANFUN)(void);
00085 typedef void      ( * IVECRANFUN)(unsigned int *, int);
00086 typedef void      ( * DVECRANFUN)(double *, int);
00087 typedef void      ( * RANSETSEEDFUN)(int *, int);
00088 
00089 void    RanSetRan(const char *sRan);
00090 void    RanSetRanExt(DRANFUN DRanFun, IRANFUN IRanFun, IVECRANFUN IVecRanFun,
00091   DVECRANFUN DVecRanFun, RANSETSEEDFUN RanSetSeedFun);
00092 double  DRanU(void);
00093 unsigned int IRanU(void);
00094 void    RanVecIntU(unsigned int *auiRan, int cRan);
00095 void    RanVecU(double *adRan, int cRan);
00096 void    RanSetSeed(int *piSeed, int cSeed);
00097 
00098 /* normal probabilities */
00099 double  DProbNormal(double x);
00100 
00101 /* polar standard normal RNG */
00102 double  FRanNormalPolar(void);
00103 double  DRanNormalPolar(void);
00104 double  FRanQuanNormal(void);
00105 double  DRanQuanNormal(void);
00106 
00107 #ifdef __cplusplus
00108 } //extern "C"
00109 #endif
00110 
00111 #endif /* INCLUDED_ZIGRANDOM_H */

Tekkotsu v4.0
Generated Thu Nov 22 00:54:57 2007 by Doxygen 1.5.4