rodrigoq/phpnetrandom

Port of .Net Random class to php


Keywords
php, random, .net, csharp, dotnet
License
Other

Documentation

PhpNetRandom

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.