lstrojny/pistis
Composer 安装命令:
composer require lstrojny/pistis
包简介
Controlled pseudo-randomness and time for PHP
README 文档
README
Pseudo-randomness
Code generation often uses random identifiers / numbers to generate identifiers that are free of collisions. These random identifiers make reproducable builds impossible since there is no way to make the randomness deterministic.
To avoid that, pistis provides a simple interface to pseudo-random numbers and hexadecimal strings that can be used
as part of identifiers enabling reproducable builds. Pistis allows passing a previous seed as an environment variable
PISTIS_SEED for a second run.
Time
A second source of quasi randomness is time. Time info can be received by calling functions like time(). By replacing
those functions with Pistis\Clock::unixTimestamp() one can fixate time for reproducible builds.
<?php include 'vendor/autoload.php'; use Pistis\PseudoRandom; use Pistis\Clock; var_dump(PseudoRandom::integer()); var_dump(PseudoRandom::integer()); var_dump(PseudoRandom::hex()); var_dump(PseudoRandom::hex()); var_dump(Clock::unixTimestamp()); echo 'PRNG seed: ' . PseudoRandom::getSeed() . "\n"; echo 'Time seed: ' . Clock::getSeed() . "\n";
Running this with PHP will output something like this:
int(1625705860186051574)
int(8240691892729656673)
string(8) "195251fc"
string(8) "1cc6a0e8"
int(1510246905)
PRNG seed: 1353038704721151717
Time seed: 1510246905
Re-running the same script with PISTIS_SEED=1353038704721151717 PISTIS_TIME=1510246905 php example.php will output
the exact same numbers again:
int(1625705860186051574)
int(8240691892729656673)
string(8) "195251fc"
string(8) "1cc6a0e8"
int(1510246905)
PRNG seed: 1353038704721151717
Time seed: 1510246905
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-09