• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ink_rand.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   Mersenne Twister declarations adapted for Traffic Server
00004 
00005   @section license License
00006 
00007    A C-program for MT19937-64 (2004/9/29 version).
00008    Coded by Takuji Nishimura and Makoto Matsumoto.
00009 
00010    This is a 64-bit version of Mersenne Twister pseudorandom number
00011    generator.
00012 
00013    Before using, initialize the state by using init_genrand64(seed)  
00014    or init_by_array64(init_key, key_length).
00015 
00016    Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura,
00017    All rights reserved.                          
00018 
00019    Redistribution and use in source and binary forms, with or without
00020    modification, are permitted provided that the following conditions
00021    are met:
00022 
00023      1. Redistributions of source code must retain the above copyright
00024         notice, this list of conditions and the following disclaimer.
00025 
00026      2. Redistributions in binary form must reproduce the above copyright
00027         notice, this list of conditions and the following disclaimer in the
00028         documentation and/or other materials provided with the distribution.
00029 
00030      3. The names of its contributors may not be used to endorse or promote 
00031         products derived from this software without specific prior written 
00032         permission.
00033 
00034    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00035    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00036    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00037    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00038    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00039    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00040    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00041    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00042    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00043    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00044    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00045 
00046    References:
00047    T. Nishimura, ``Tables of 64-bit Mersenne Twisters''
00048      ACM Transactions on Modeling and 
00049      Computer Simulation 10. (2000) 348--357.
00050    M. Matsumoto and T. Nishimura,
00051      ``Mersenne Twister: a 623-dimensionally equidistributed
00052        uniform pseudorandom number generator''
00053      ACM Transactions on Modeling and 
00054      Computer Simulation 8. (Jan. 1998) 3--30.
00055 
00056    Any feedback is very welcome.
00057    http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html
00058    email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces)
00059 */
00060 
00061 #ifndef __INK_RAND_H__
00062 #define __INK_RAND_H__
00063 
00064 
00065 #include "ink_defs.h"
00066 #include "ink_apidefs.h"
00067 
00068 
00069 class InkRand
00070 {
00071 public:
00072   InkRand(uint64_t d);
00073 
00074   void seed(uint64_t d);
00075   inkcoreapi uint64_t random();
00076   double drandom();
00077 
00078 private:
00079   uint64_t mt[312];
00080   int mti;
00081 };
00082 
00083 inline int ink_rand_r(uint32_t * p) {
00084   return (((*p) = (*p) * 1103515245 + 12345) % ((uint32_t) 0x7fffffff + 1));
00085 }
00086 
00087 #endif /* __INK_RAND_H__ */
00088 

Generated by  doxygen 1.7.1