-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |