Coverage Report

Created: 2022-02-19 20:31

/src/php-src/ext/standard/rand.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright (c) The PHP Group                                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to version 3.01 of the PHP license,      |
6
   | that is bundled with this package in the file LICENSE, and is        |
7
   | available through the world-wide-web at the following url:           |
8
   | http://www.php.net/license/3_01.txt                                  |
9
   | If you did not receive a copy of the PHP license and are unable to   |
10
   | obtain it through the world-wide-web, please send a note to          |
11
   | license@php.net so we can mail you a copy immediately.               |
12
   +----------------------------------------------------------------------+
13
   | Authors: Rasmus Lerdorf <rasmus@php.net>                             |
14
   |          Zeev Suraski <zeev@php.net>                                 |
15
   |          Pedro Melo <melo@ip.pt>                                     |
16
   |          Sterling Hughes <sterling@php.net>                          |
17
   |                                                                      |
18
   | Based on code from: Richard J. Wagner <rjwagner@writeme.com>         |
19
   |                     Makoto Matsumoto <matumoto@math.keio.ac.jp>      |
20
   |                     Takuji Nishimura                                 |
21
   |                     Shawn Cokus <Cokus@math.washington.edu>          |
22
   +----------------------------------------------------------------------+
23
 */
24
25
#include "php.h"
26
#include "php_rand.h"
27
#include "php_mt_rand.h"
28
29
/* {{{ php_srand */
30
PHPAPI void php_srand(zend_long seed)
31
0
{
32
0
  php_mt_srand(seed);
33
0
}
34
/* }}} */
35
36
/* {{{ php_rand */
37
PHPAPI zend_long php_rand(void)
38
0
{
39
0
  return php_mt_rand();
40
0
}
41
/* }}} */
42
43
/* {{{ Returns a random number from Mersenne Twister */
44
PHP_FUNCTION(rand)
45
220
{
46
220
  zend_long min;
47
220
  zend_long max;
48
220
  int argc = ZEND_NUM_ARGS();
49
50
220
  if (argc == 0) {
51
0
    RETURN_LONG(php_mt_rand() >> 1);
52
0
  }
53
54
660
  ZEND_PARSE_PARAMETERS_START(2, 2)
55
220
    Z_PARAM_LONG(min)
56
440
    Z_PARAM_LONG(max)
57
220
  ZEND_PARSE_PARAMETERS_END();
58
59
220
  if (max < min) {
60
2
    RETURN_LONG(php_mt_rand_common(max, min));
61
2
  }
62
63
218
  RETURN_LONG(php_mt_rand_common(min, max));
64
218
}
65
/* }}} */