Skip to content

Commit

Permalink
v1-release (#1)
Browse files Browse the repository at this point in the history
* Document library with example

* Attempt CI config

* Only hash composer.lock file

* Remove cache from build step

* Test job depends on build job

* Persist working directory

* Use current directory for artifacts

* Add installation section
  • Loading branch information
g105b authored Feb 13, 2020
1 parent f8a459c commit 065b561
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v1

- name: Persist working directory
uses: actions/upload-artifact@v1
with:
name: pwd
path: ./

test:
runs-on: ubuntu-latest
needs: build

steps:
- name: Download persisted dependencies
uses: actions/download-artifact@v1
with:
name: pwd
path: ./

- uses: php-actions/phpunit@v1
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
Deterministic random number generator
=====================================

This library generates byte sequences with the ability to convert to integers and floating points. The sequences generated appear to be random, but can be fully determined by providing a known seed value. The main use of this library is in procedural generation algorithms.

The cryptographic algorithms provided by OpenSSL are used to generate the random data, specifically using the Advanced Encryption Standard (AES) operating in Galois/Counter mode (GCM).

Each instance of the `Random` class maintains its AES counter, so there is theoretically no limit to the amount of random data produced. The deterministic nature of this library is possible due to the counter's persistence while generating the initialisation vector, along with the encryption key being set from a provided seed value.

*****

Installation
------------

Composer can be used to install this library into your project. `composer require g105b/drng` will install the latest version. Alternatively, you can modify your project's `composer.json` manually:

```json
{
"require": {
"g105b/drng": "1.*"
}
}
```

Usage example
-------------

### Using a string seed to determine the random sequence

`string-seed.php`:

```php
use g105b\drng\Random;
use g105b\drng\StringSeed;

$rand = new Random(
new StringSeed("i like cats")
);

echo "Random sequence: ";

for($i = 0; $i < 10; $i++) {
if($i > 0) {
echo ", ";
}

echo $rand->getInt(1, 10);
}
```

The above example will always output the same sequence, due to the use of the seed "i like cats":

```
Random sequence: 1, 9, 7, 6, 5, 6, 8, 10, 2, 5
```
19 changes: 19 additions & 0 deletions example/string-seed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
require __DIR__ . "/../vendor/autoload.php";

use g105b\drng\Random;
use g105b\drng\StringSeed;

$rand = new Random(
new StringSeed("i like cats")
);

echo "Random sequence: ";

for($i = 0; $i < 10; $i++) {
if($i > 0) {
echo ", ";
}

echo $rand->getInt(1, 10);
}

0 comments on commit 065b561

Please sign in to comment.