lstrojny/pistis 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固