home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / MATH / ULTRA101.ZIP / ULTRA.DOC < prev    next >
Encoding:
Text File  |  1992-03-26  |  8.5 KB  |  194 lines

  1. ; Program:      ULTRA.ASM
  2. ;
  3. ; Description:  The greatest random number generator that ever was
  4. ;               or ever will be.  Way beyond Super-Duper.
  5. ;               (Just kidding, but we think its a good one.)
  6. ; Authors:      Arif Zaman (arif@stat.fsu.edu) and
  7. ;               George Marsaglia (geo@stat.fsu.edu).
  8. ; Date:         18 March 1992
  9. ; Version:      1.01 (first public release)
  10. ; Copyright:    To obtain permission to incorporate this program into
  11. ;               any commercial product, please contact the authors at
  12. ;               the e-mail address given above or at
  13. ;
  14. ;               Department of Statistics and
  15. ;               Supercomputer Computations Research Institute
  16. ;               Florida State University
  17. ;               Tallahassee, FL 32306.
  18. ;
  19. ; CONTENTS:  1. Detailed Description
  20. ;            2. Compilation Instructions
  21. ;            3. Functions and Subroutines
  22. ;            4. Program Structure
  23. ;
  24. ;----------------------------------------------------------------------
  25. ; 1. DETAILED DESCRIPTION:
  26. ;
  27. ; This is an implementation of a random number generator with many
  28. ; good properties that common generators lack, namely:
  29. ;
  30. ;     o  Extremely long period (more than 10^356---that's more than
  31. ;        10^270 numbers for each atom in the universe, in case you
  32. ;         want to simulate creation).
  33. ;
  34. ;     o  Combines two different types of generators, to achieve a very
  35. ;        thorough mixing.
  36. ;
  37. ;     o  Very fast.
  38. ;
  39. ;     o  Random bits, bytes, 16 or 32 bit words, single or double precision
  40. ;        real numbers are all available.
  41. ;
  42. ;     o  Single precision reals (by far the most common) are guaranteed
  43. ;        to have full precision in the fraction (mantissa).
  44. ;        Almost all generators  produce reals by dividing a 32 (or 31) bit
  45. ;        integer by 2^32 (2^31).  This means the smallest possible
  46. ;        random reals are small multiples of 2^(-32).  This implementation
  47. ;        will produce random reals down to 2^(-50) or smaller with the proper
  48. ;        frequencies.  This makes it impossible to get a 0, which
  49. ;        avoids the rare, but irritating program-stopping situation
  50. ;        that arises from taking a logarithm of, or dividing by, zero.
  51. ;
  52. ; The principal component of ULTRA is the Subtract-with-Borrow
  53. ; (SWB) generator that is described in our paper `A New Class of
  54. ; Random Number Generators', Annals of Applied Probability V1 462-480, 1991.
  55. ; This uses a 148 byte seed array, to obtain an astronomically large
  56. ; period, while satisfying all the usual theoretical and experimental
  57. ; tests for randomness.
  58. ;
  59. ; The other component of ULTRA is the congruential generator with
  60. ; multiplier 69069 and base 2^32. This is a very well known, reliable
  61. ; (but short period) generator, tried and tested.
  62. ; It is ,for example, the generator built into VAX's.
  63. ; The results of both of these generators are xor'ed to provide the
  64. ; bytes which form the output of the ULTRA random number generator.
  65. ;
  66. ;----------------------------------------------------------------------
  67. ; 2. COMPILATION INSTRUCTIONS
  68. ;
  69. ; This assembler code is written for TASM 2.0, to allow one program
  70. ; to serve for many different languages.
  71. ;
  72. ; The header files define language dependent macros. These are:
  73. ; ULTRA_C.ASM, ULTRA_TP.ASM and ULTRA_LH.ASM are for Turbo C, 
  74. ; Turbo Pascal and Lahey Fortran respectively.
  75. ;
  76. ; All of these files then include the core files ULTRADAT.INC and
  77. ; ULTRACOD.INC, which actually implementat the algorithm.
  78. ;
  79. ; A second set of files ULT32_C.ASM, ULT32_TP.ASM, and ULT32_LH.ASM
  80. ; which include ULT32DAT.INC and ULT32COR.INC are the same programs
  81. ; rewritten to use 32 bit code available on 80386 or 80486 machines
  82. ; for faster execution.
  83. ;
  84. ; The C files ULTRA_C.ASM and ULT32_C.ASM depend on the user defining
  85. ; a variable `m' to be the memory model. Thus the command:
  86. ;    TASM -dm=small ULTRA_C.ASM
  87. ; will create a small memory model object file. The memory model can
  88. ; be any of `tiny', `small', `compact', `medium', `large' or `huge'.
  89. ;
  90. ; Implementation in any other language is simply a matter of fixing
  91. ; the header file.
  92. ;
  93. ;----------------------------------------------------------------------
  94. ; 3. FUNCTIONS and SUBROUTINES
  95. ;
  96. ;  The i[n]bit functions:
  97. ;    i1bit, i7bit, i8bit, i15bit, i16bit, i31bit, i32bit
  98. ;
  99. ;    For n=32, 16, 8 these return a 4, 2, 1 byte answer which has
  100. ;    all bits random, hence is a random integer. If it is treated
  101. ;    as a signed integer, it ranges from -2^(n-1) to 2^(n-1)-1.
  102. ;    As an unsigned integer it range is 0 to 2^n-1.
  103. ;
  104. ;    For n=31, 15, 7 these return a 4, 2, 1 byte answer, but since
  105. ;    the sign bit is always off, these are always positive integers
  106. ;    from 0 and 2^n-1.
  107. ;
  108. ;  [d][u/v]ni functions:
  109. ;
  110. ;    uni() is a single precision uniform random number strictly
  111. ;     between 0 and 1.  uni() always has 24 bits of precision;
  112. ;     it will never be 0 (or 1).
  113. ;
  114. ;    vni() is a single precision uniform between -1 and 1. It always has
  115. ;          24 bits of precision, and it never takes on the extreme values.
  116. ;
  117. ;    duni() and dvni() are double precision version of uni and vni.
  118. ;          They have no more than 64 bits of precision.
  119. ;
  120. ;  rinit(n1,n2)
  121. ;
  122. ;    Calling rinit(n1,n2) initializes the seed array, using
  123. ;    the two 32-bit integer arguments n1 and n2.
  124. ;    The first argument should be odd (if it isn't it is made so).
  125. ;    If rinit is not called, the built-in default state is
  126. ;    what would result from the call rinit(1234567,7654321).
  127. ;
  128. ;  The variables swbn and swbx and the subroutine swbfill() are
  129. ;    declared globally to allow macros to implement even faster
  130. ;    versions of these subroutines. swbx is an array of 148 bytes
  131. ;    that is filled with random bytes every time swbfill is called.
  132. ;    swbn is a 16-bit integer that counts how many bytes of swbx
  133. ;    have not yet been used by any of the random functions.
  134. ;
  135. ;  An example of a macro in C that provides 32-bit integers is given
  136. ;    below. Note that this is written assuming no other random
  137. ;    routines are being used at the same time.
  138. ;
  139. ;    extern long swbx[37];
  140. ;    short  int  nlft = 0;
  141. ;           long swbp
  142. ;    #define i32bit() ( (--nlft >= 0) ?  *(swbp++) : \
  143. ;     swbfill(), nlft=36, swbp=&swbx[0], *(swbp++) )
  144. ;
  145. ;    Speed comes from the fact that, 36 out of 37 times, there need
  146. ;    be no subroutine call at all, just a simple table lookup.
  147. ;    (The overhead of function calls can take as many cycles
  148. ;    as the generating process itself.)
  149. ;
  150. ;  The data is laid out in such a way that if swbx is declared as
  151. ;    an array containing 306 bytes, this array would contain the
  152. ;    entire state of the random number generator. Thus, saving
  153. ;    and then later restoring these 306 bytes would allow one to
  154. ;    continue exactly where the process had left off.
  155. ;
  156. ;----------------------------------------------------------------------
  157. ;
  158. ; 4. DATA
  159. ;     The array swbx has 148 random bytes in it. All the functions
  160. ;     take as many bytes as they need from it. swbn is the number of
  161. ;     bytes remaining in that array. When this gets to zero, the
  162. ;     fillswb routine refills them with a fresh batch of 148 bytes.
  163. ;
  164. ;----------------------------------------------------------------------
  165. ; 5. Header files
  166. ;     This is where all language-dependent entry and exit conventions
  167. ;     have been placed. If you want to add another language which uses
  168. ;     another protocol to pass arguments, return values, or save registers,
  169. ;     this is where you want to modify the program.
  170. ;
  171. ;     You must define:
  172. ;    EnterProcedure    Called every time a procedure is entered
  173. ;        save all registers etc here. Make DS point to the
  174. ;        data segement if it doesn't.
  175. ;    ExitProcedure    Called every time a procedure exits
  176. ;        undo all that EnterProcdure did here.
  177. ;    RinitProcStart    Loads the two arguments for RINIT into
  178. ;        CONGX and SHRGX (for ULTRA), and into the
  179. ;        32-bit registers EAX and EBX (for ULT32).
  180. ;        Make sure ES=DS.
  181. ;    RinitProcEnd    Undo what RinitProcStart did.
  182. ;    FillProcStart    Make sure ES=DS.
  183. ;    FillProcEnd    Undo what FillProcStart did.
  184. ;    DwordFn        The function result is in DX:AX. Place it
  185. ;            where the language expects it to be.
  186. ;    WordFn        Put result in AX where it is expected.
  187. ;    ByteFn        Put result in AL where it is expected.
  188. ;    RealFn,DoubleFn Put result from the NDP stack to where it should be.
  189. ;
  190. ;     The segment names, classes etc must also be defined here.
  191. ;    The files ULTRADAT.INC and ULTRACOD.INC (or ULT32DAT.INC
  192. ;    and ULT32COD.INC) must be included in the appropriate
  193. ;    segments. Look at examples of header files for more information.
  194.