Annotation of embedaddon/php/ext/standard/php_rand.h, revision 1.1.1.3

1.1       misho       1: /*
                      2:    +----------------------------------------------------------------------+
                      3:    | PHP Version 5                                                        |
                      4:    +----------------------------------------------------------------------+
1.1.1.3 ! misho       5:    | Copyright (c) 1997-2013 The PHP Group                                |
1.1       misho       6:    +----------------------------------------------------------------------+
                      7:    | This source file is subject to version 3.01 of the PHP license,      |
                      8:    | that is bundled with this package in the file LICENSE, and is        |
                      9:    | available through the world-wide-web at the following url:           |
                     10:    | http://www.php.net/license/3_01.txt                                  |
                     11:    | If you did not receive a copy of the PHP license and are unable to   |
                     12:    | obtain it through the world-wide-web, please send a note to          |
                     13:    | license@php.net so we can mail you a copy immediately.               |
                     14:    +----------------------------------------------------------------------+
                     15:    | Authors: Rasmus Lerdorf <rasmus@php.net>                             |
                     16:    |          Zeev Suraski <zeev@zend.com>                                |
                     17:    |          Pedro Melo <melo@ip.pt>                                     |
                     18:    |          Sterling Hughes <sterling@php.net>                          |
                     19:    |                                                                      |
                     20:    | Based on code from: Shawn Cokus <Cokus@math.washington.edu>          |
                     21:    +----------------------------------------------------------------------+
                     22:  */
1.1.1.2   misho      23: /* $Id$ */
1.1       misho      24: 
                     25: #ifndef PHP_RAND_H
                     26: #define        PHP_RAND_H
                     27: 
                     28: #include <stdlib.h>
                     29: #include "basic_functions.h"
                     30: 
                     31: /* System Rand functions */
                     32: #ifndef RAND_MAX
                     33: #define RAND_MAX (1<<15)
                     34: #endif
                     35: 
                     36: /* In ZTS mode we rely on rand_r() so we must use RAND_MAX. */
                     37: #if !defined(ZTS) && (defined(HAVE_LRAND48) || defined(HAVE_RANDOM))
                     38: #define PHP_RAND_MAX 2147483647
                     39: #else
                     40: #define PHP_RAND_MAX RAND_MAX
                     41: #endif
                     42: 
                     43: #define RAND_RANGE(__n, __min, __max, __tmax) \
                     44:     (__n) = (__min) + (long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0)))
                     45: 
                     46: /* MT Rand */
                     47: #define PHP_MT_RAND_MAX ((long) (0x7FFFFFFF)) /* (1<<31) - 1 */ 
                     48: 
                     49: #ifdef PHP_WIN32
                     50: #define GENERATE_SEED() (((long) (time(0) * GetCurrentProcessId())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C))))
                     51: #else
                     52: #define GENERATE_SEED() (((long) (time(0) * getpid())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C))))
                     53: #endif
                     54: 
                     55: PHPAPI void php_srand(long seed TSRMLS_DC);
                     56: PHPAPI long php_rand(TSRMLS_D);
                     57: PHPAPI void php_mt_srand(php_uint32 seed TSRMLS_DC);
                     58: PHPAPI php_uint32 php_mt_rand(TSRMLS_D);
                     59: 
                     60: #endif /* PHP_RAND_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>