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 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024   
00025 #ifdef __LP64__
00026   typedef unsigned long UINT64;
00027   typedef          long INT64;
00028   #define LIT_UINT64(c) (c##ul)
00029   #define LIT_INT64(c)  (c##l)
00030 #elif defined(_MSC_VER)
00031   typedef unsigned __int64 UINT64;
00032   typedef          __int64 INT64;
00033   #define LIT_UINT64(c) (c##ui64)
00034   #define LIT_INT64(c)  (c##i64)
00035 #else 
00036   typedef unsigned long long UINT64;
00037   typedef          long long INT64;
00038   #define LIT_UINT64(c) (c##ull)
00039   #define LIT_INT64(c)  (c##ll)
00040 #endif
00041 
00042 #define M_RAN_INVM30  9.31322574615478515625e-010       /* 1.0 / 2^30 */
00043 #define M_RAN_INVM32  2.32830643653869628906e-010       /* 1.0 / 2^32 */
00044 #define M_RAN_INVM48  3.55271367880050092936e-015       /* 1.0 / 2^48 */
00045 #define M_RAN_INVM52  2.22044604925031308085e-016       /* 1.0 / 2^52 */
00046 #define M_RAN_INVM64  5.42101086242752217004e-020       /* 1.0 / 2^64 */
00047 
00048 #define RANDBL_32old(iRan1)           \
00049     ((unsigned int)(iRan1) * M_RAN_INVM32)
00050 #define RANDBL_48old(iRan1, iRan2)      \
00051     ((unsigned int)(iRan1) + (unsigned int)((iRan2) << 16) \
00052     * M_RAN_INVM32) * M_RAN_INVM32
00053 #define RANDBL_52old(iRan1, iRan2)      \
00054     ((unsigned int)(iRan1) + (unsigned int)((iRan2) << 12) \
00055     * M_RAN_INVM32) * M_RAN_INVM32
00056 
00057 #define RANDBL_32new(iRan1)                   \
00058     ((int)(iRan1) * M_RAN_INVM32 + (0.5 + M_RAN_INVM32 / 2))
00059 #define RANDBL_48new(iRan1, iRan2)            \
00060     ((int)(iRan1) * M_RAN_INVM32 + (0.5 + M_RAN_INVM48 / 2) + \
00061         (int)((iRan2) & 0x0000FFFF) * M_RAN_INVM48)
00062 #define RANDBL_52new(iRan1, iRan2)            \
00063     ((int)(iRan1) * M_RAN_INVM32 + (0.5 + M_RAN_INVM52 / 2) + \
00064         (int)((iRan2) & 0x000FFFFF) * M_RAN_INVM52)
00065 
00066 void  GetInitialSeeds(unsigned int auiSeed[], int cSeed,
00067   unsigned int uiSeed, unsigned int uiMin);
00068 
00069 /* MWC8222 George Marsaglia */
00070 void RanSetSeed_MWC8222(int *piSeed, int cSeed);
00071 unsigned int IRan_MWC8222(void);
00072 double DRan_MWC8222(void);
00073 void VecIRan_MWC8222(unsigned int *auiRan, int cRan);
00074 void VecDRan_MWC8222(double *adRan, int cRan);
00075 
00076 /* plug-in RNG */
00077 typedef double    ( * DRANFUN)(void);
00078 typedef unsigned int( * IRANFUN)(void);
00079 typedef void      ( * IVECRANFUN)(unsigned int *, int);
00080 typedef void      ( * DVECRANFUN)(double *, int);
00081 typedef void      ( * RANSETSEEDFUN)(int *, int);
00082 
00083 void    RanSetRan(const char *sRan);
00084 void    RanSetRanExt(DRANFUN DRanFun, IRANFUN IRanFun, IVECRANFUN IVecRanFun,
00085   DVECRANFUN DVecRanFun, RANSETSEEDFUN RanSetSeedFun);
00086 double  DRanU(void);
00087 unsigned int IRanU(void);
00088 void    RanVecIntU(unsigned int *auiRan, int cRan);
00089 void    RanVecU(double *adRan, int cRan);
00090 void    RanSetSeed(int *piSeed, int cSeed);
00091 
00092 /* normal probabilities */
00093 double  DProbNormal(double x);
00094 
00095 /* polar standard normal RNG */
00096 double  FRanNormalPolar(void);
00097 double  DRanNormalPolar(void);
00098 double  FRanQuanNormal(void);
00099 double  DRanQuanNormal(void);
00100 
00101 #ifdef __cplusplus
00102 } //extern "C"
00103 #endif
00104 
00105 #endif /* INCLUDED_ZIGRANDOM_H */

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:53 2016 by Doxygen 1.6.3