Skip to content

Commit

Permalink
Random Extension: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zeriyoshi committed Jul 7, 2021
1 parent 3ccc236 commit af5b15f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ext/random_ext/php_random_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ PHPAPI zend_long php_random_range(php_random *random, zend_long min, zend_long m
PHPAPI void php_random_array_data_shuffle(php_random *random, zval *array);
PHPAPI void php_random_string_shuffle(php_random *random, char *str, zend_long len);

#endif /* PHP_RANDOM_H_MODULE */
#endif /* PHP_RANDOM_EXT_H */
46 changes: 45 additions & 1 deletion ext/random_ext/random_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,50 @@
+----------------------------------------------------------------------+
*/

/*
The following functions are based on a C++ class MTRand by
Richard J. Wagner. For more information see the web page at
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/MersenneTwister.h
Mersenne Twister random number generator -- a C++ class MTRand
Based on code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus
Richard J. Wagner v1.0 15 May 2003 rjwagner@writeme.com
The Mersenne Twister is an algorithm for generating random numbers. It
was designed with consideration of the flaws in various other generators.
The period, 2^19937-1, and the order of equidistribution, 623 dimensions,
are far greater. The generator is also fast; it avoids multiplication and
division, and it benefits from caches and pipelines. For more information
see the inventors' web page at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
Reference
M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on
Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
Copyright (C) 2000 - 2003, Richard J. Wagner
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
Expand Down Expand Up @@ -779,7 +823,7 @@ PHP_METHOD(Random, __unserialize)
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(random_ext)
{
/* Random\NumberGenerator\RandomNumberGenerator */
/* Random\NumberGenerator */
random_ce_Random_NumberGenerator = register_class_Random_NumberGenerator();

/* Random\NumberGenerator\XorShift128Plus */
Expand Down
2 changes: 1 addition & 1 deletion ext/random_ext/random_ext.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function generate(): int {}
final class Random
{
// FIXME: stub generator (gen_stub.php) does not supported.
// private Random\NumberGenerator\RandomNumberGenerator $rng;
// private Random\NumberGeneratorm $rng;
private mixed $rng;

public function __construct(?Random\NumberGenerator $rng = null) {}
Expand Down
2 changes: 1 addition & 1 deletion ext/random_ext/random_ext_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: d5f5afc735100bce1a76f2a16522c5832a65b2f0 */
* Stub hash: 72e03ec3a21486d6426fc0658f0c133247da141f */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Random_NumberGenerator_generate, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
Expand Down

0 comments on commit af5b15f

Please sign in to comment.