2017 © Pedro Peláez
 

library pistis

Controlled pseudo-randomness and time for PHP

image

lstrojny/pistis

Controlled pseudo-randomness and time for PHP

  • Monday, June 25, 2018
  • by lstrojny
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Pistis - Controlled pseudo-randomness and time for PHP Build Status

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., (*1)

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., (*2)

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., (*3)

<?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:, (*4)

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:, (*5)

int(1625705860186051574)
int(8240691892729656673)
string(8) "195251fc"
string(8) "1cc6a0e8"
int(1510246905)
PRNG seed: 1353038704721151717
Time seed: 1510246905

The Versions

25/06 2018

dev-master

9999999-dev

Controlled pseudo-randomness and time for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

09/11 2017

v0.4

0.4.0.0

Controlled pseudo-randomness and time for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

09/11 2017

v0.3

0.3.0.0

Seed based pseudo-randomness generation

  Sources   Download

MIT

The Requires

 

The Development Requires

09/11 2017

v0.2

0.2.0.0

Seed based pseudo-randomness generation

  Sources   Download

MIT

The Requires

 

The Development Requires

09/11 2017

v0.1

0.1.0.0

Seed based pseudo-randomness generation

  Sources   Download

MIT

The Requires

 

The Development Requires