rodrigoq/phpnetrandom

Port of .Net Random class to php

1.0 2019-10-26 15:09 UTC

This package is not auto-updated.

Last update: 2024-11-21 15:50:44 UTC


README

A port of .Net Random class to php. Useful for migration purposes or comparison. Using the same seed, you get the same random values on .Net and php.

Installation

PhpNetRandom has no external dependencies. It can be included in a project directly adding this line to a php file:

<?php
include 'NetRandom.php';

It's also available on Packagist, and can be installed via Composer. Just add this line to your composer.json file:

"rodrigoq/phpnetrandom": "~1.0"

or run

composer require rodrigoq/phpnetrandom

Details

The NetRandom.php class is a direct port of the public code of original C# .Net Random class.

There are many tests that can be run with PHPUnit. There is also a C# .Net solution with a Random command line utility for testing purposes. To run the full test suite you have to compile that solution.

Usage

<?php

include 'NetRandom.php';

use NetRandom\NetRandom;

$random = new NetRandom(); //seed is optional.

// You can add max or, min and max parameters.
echo $random->Next() . PHP_EOL;

echo $random->NextDouble() . PHP_EOL;

$bytes = array_fill(0, 10, 0);
$random->NextBytes($bytes);
var_dump($bytes);

License

This software is distributed under the LGPL 3.0 license. Please read LICENSE for information on the software availability and distribution.