Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LinearCongruentialGenerator
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 bsd
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 msvcrt
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Utils\RnG
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\Utils\RnG;
16
17/**
18 * Linear congruential generator class
19 *
20 * @package phpOMS\Utils\RnG
21 * @license OMS License 2.0
22 * @link    https://jingga.app
23 * @since   1.0.0
24 */
25class LinearCongruentialGenerator
26{
27    /**
28     * BSD seed value.
29     *
30     * @var int
31     * @since 1.0.0
32     */
33    private static $bsdSeed = 0;
34
35    /**
36     * MSVCRT seed value.
37     *
38     * @var int
39     * @since 1.0.0
40     */
41    private static $msvcrtSeed = 0;
42
43    /**
44     * BSD random number
45     *
46     * @param int $seed Starting seed
47     *
48     * @return int
49     *
50     * @since 1.0.0
51     */
52    public static function bsd(int $seed = 0) : int
53    {
54        if ($seed !== 0) {
55            self::$bsdSeed = $seed;
56        }
57
58        return self::$bsdSeed = (1103515245 * self::$bsdSeed + 12345) % (1 << 31);
59    }
60
61    /**
62     * MS random number
63     *
64     * @param int $seed Starting seed
65     *
66     * @return int
67     *
68     * @since 1.0.0
69     */
70    public static function msvcrt(int $seed = 0) : int
71    {
72        if ($seed !== 0) {
73            self::$msvcrtSeed = $seed;
74        }
75
76        return (self::$msvcrtSeed = (214013 * self::$msvcrtSeed + 2531011) % (1 << 31)) >> 16;
77    }
78}