Back to index

php5  5.3.10
php_rand.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Rasmus Lerdorf <rasmus@php.net>                             |
00016    |          Zeev Suraski <zeev@zend.com>                                |
00017    |          Pedro Melo <melo@ip.pt>                                     |
00018    |          Sterling Hughes <sterling@php.net>                          |
00019    |                                                                      |
00020    | Based on code from: Shawn Cokus <Cokus@math.washington.edu>          |
00021    +----------------------------------------------------------------------+
00022  */
00023 /* $Id: php_rand.h 321634 2012-01-01 13:15:04Z felipe $ */
00024 
00025 #ifndef PHP_RAND_H
00026 #define       PHP_RAND_H
00027 
00028 #include <stdlib.h>
00029 #include "basic_functions.h"
00030 
00031 /* System Rand functions */
00032 #ifndef RAND_MAX
00033 #define RAND_MAX (1<<15)
00034 #endif
00035 
00036 /* In ZTS mode we rely on rand_r() so we must use RAND_MAX. */
00037 #if !defined(ZTS) && (defined(HAVE_LRAND48) || defined(HAVE_RANDOM))
00038 #define PHP_RAND_MAX 2147483647
00039 #else
00040 #define PHP_RAND_MAX RAND_MAX
00041 #endif
00042 
00043 #define RAND_RANGE(__n, __min, __max, __tmax) \
00044     (__n) = (__min) + (long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0)))
00045 
00046 /* MT Rand */
00047 #define PHP_MT_RAND_MAX ((long) (0x7FFFFFFF)) /* (1<<31) - 1 */ 
00048 
00049 #ifdef PHP_WIN32
00050 #define GENERATE_SEED() (((long) (time(0) * GetCurrentProcessId())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C))))
00051 #else
00052 #define GENERATE_SEED() (((long) (time(0) * getpid())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C))))
00053 #endif
00054 
00055 PHPAPI void php_srand(long seed TSRMLS_DC);
00056 PHPAPI long php_rand(TSRMLS_D);
00057 PHPAPI void php_mt_srand(php_uint32 seed TSRMLS_DC);
00058 PHPAPI php_uint32 php_mt_rand(TSRMLS_D);
00059 
00060 #endif /* PHP_RAND_H */