Nori
|
00001 /* 00002 This file is part of Nori, a simple educational ray tracer 00003 00004 Copyright (c) 2012 by Wenzel Jakob and Steve Marschner. 00005 00006 Nori is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License Version 3 00008 as published by the Free Software Foundation. 00009 00010 Nori is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #if !defined(__RANDOM_H) 00020 #define __RANDOM_H 00021 00022 #include <nori/common.h> 00023 00024 NORI_NAMESPACE_BEGIN 00025 00026 /* Period parameters for the Mersenne Twister RNG */ 00027 #define MT_N 624 00028 #define MT_M 397 00029 #define MT_MATRIX_A 0x9908b0dfUL /* constant vector a */ 00030 #define MT_UPPER_MASK 0x80000000UL /* most significant w-r bits */ 00031 #define MT_LOWER_MASK 0x7fffffffUL /* least significant r bits */ 00032 00033 /** 00034 * \brief Mersenne Twister: pseudorandom number generator based on a 00035 * twisted generalized feedback shift register 00036 * 00037 * Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, 00038 * All rights reserved. 00039 */ 00040 class Random { 00041 public: 00042 /// Create an uninitialized instance 00043 Random(); 00044 00045 /// Seed the RNG with the specified seed value 00046 void seed(uint32_t value); 00047 00048 /// Seed the RNG with an entire array 00049 void seed(uint32_t *values, int length); 00050 00051 /// Seed the RNG using an existing instance 00052 void seed(Random *random); 00053 00054 /// Generate an uniformly distributed 32-bit integer 00055 uint32_t nextUInt(); 00056 00057 /// Generate an uniformly distributed single precision value on [0,1) 00058 float nextFloat(); 00059 private: 00060 uint32_t m_mt[MT_N]; 00061 int m_mti; 00062 }; 00063 00064 NORI_NAMESPACE_END 00065 00066 #endif /* __RANDOM_H */