1 /* 2 This file is part of cave9. 3 4 cave9 is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 cave9 is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with cave9. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #include "detrand.h" 18 19 int randval; 20 int randseed; 21 detrand()22float detrand() 23 { 24 // taken from http://freespace.virgin.net/hugo.elias/models/m_perlin.htm 25 randval++; 26 randval = (randval<<13) ^ randval; 27 return ( 1.0 - ( (randval * (randval * randval * randseed * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); 28 } 29 detsrand(int seed)30void detsrand(int seed) 31 { 32 randseed = seed; 33 randval = 0; 34 } 35 36