1 /* (C) Copyright 2004, 2005, 2006, 2007, 2008, 2009 Stijn van Dongen 2 * 3 * This file is part of tingea. You can redistribute and/or modify tingea 4 * under the terms of the GNU General Public License; either version 3 of the 5 * License or (at your option) any later version. You should have received a 6 * copy of the GPL along with tingea, in the file COPYING. 7 */ 8 9 #ifndef tingea_rand_h 10 #define tingea_rand_h 11 12 #include <stdlib.h> 13 14 15 #define MCX_RAND_MAX RAND_MAX 16 17 #define mcxUniform0 ((1.0 * random()) / ((double) RAND_MAX + 1.0)) 18 #define mcxUniform1 (1.0 - ((1.0 * random()) / ((double) RAND_MAX + 1.0))) 19 20 21 /* This is for weak seeding, to obtain fresh seeds which will definitely 22 * *not* be suitable for cryptographic needs 23 */ 24 25 unsigned long mcxSeed 26 ( unsigned long seedlet 27 ) ; 28 29 30 double mcxNormal 31 ( void 32 ) ; 33 34 double mcxNormalCut 35 ( double radius 36 , double stddev 37 ) ; 38 39 double mcxNormalZiggurat 40 ( void 41 ) ; 42 43 double mcxNormalBoxMuller 44 ( void 45 ) ; 46 47 48 /* Generate numbers in the interval [-outer, outer] according 49 * to the normal distribution with standard deviation sigma. 50 * Use e.g. outer = 2.0 sigma = 0.5 51 */ 52 53 double mcxNormalSample 54 ( double radius 55 , double stddev 56 ) ; 57 58 59 #endif 60 61