PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/standard/php_rand.h

http://github.com/infusion/PHP
C Header | 60 lines | 25 code | 9 blank | 26 comment | 2 complexity | 2f843268dabb5177d2430c9593cd921d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2011 The PHP Group |
  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. */
  23. /* $Id: php_rand.h 306939 2011-01-01 02:19:59Z felipe $ */
  24. #ifndef PHP_RAND_H
  25. #define PHP_RAND_H
  26. #include <stdlib.h>
  27. #include "basic_functions.h"
  28. /* System Rand functions */
  29. #ifndef RAND_MAX
  30. #define RAND_MAX (1<<15)
  31. #endif
  32. /* In ZTS mode we rely on rand_r() so we must use RAND_MAX. */
  33. #if !defined(ZTS) && (defined(HAVE_LRAND48) || defined(HAVE_RANDOM))
  34. #define PHP_RAND_MAX 2147483647
  35. #else
  36. #define PHP_RAND_MAX RAND_MAX
  37. #endif
  38. #define RAND_RANGE(__n, __min, __max, __tmax) \
  39. (__n) = (__min) + (long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0)))
  40. /* MT Rand */
  41. #define PHP_MT_RAND_MAX ((long) (0x7FFFFFFF)) /* (1<<31) - 1 */
  42. #ifdef PHP_WIN32
  43. #define GENERATE_SEED() (((long) (sapi_get_request_time(TSRMLS_C) * GetCurrentProcessId())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C))))
  44. #else
  45. #define GENERATE_SEED() (((long) (sapi_get_request_time(TSRMLS_C) * getpid())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C))))
  46. #endif
  47. PHPAPI void php_srand(long seed TSRMLS_DC);
  48. PHPAPI long php_rand(TSRMLS_D);
  49. PHPAPI void php_mt_srand(php_uint32 seed TSRMLS_DC);
  50. PHPAPI php_uint32 php_mt_rand(TSRMLS_D);
  51. #endif /* PHP_RAND_H */