PHP code example of leigh / mt-rand

1. Go to this page and download the library: Download leigh/mt-rand library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

leigh / mt-rand example snippets


$mt = new \MersenneTwister\MT();
$mt->init(1234); // mt_srand(1234);
$mt->int31();    // int31() per mt19937ar.c, positive values only
$mt->int32();    // int32() per mt19937ar.c, high bit sets sign

$mt = new \MersenneTwister\MT64();
$mt->init(1234);
$mt->int63();    // int63() per mt19937-64.c, positive values only
$mt->int64();    // int64() per mt19937-64.c, high bit sets sign

$mt = new \MersenneTwister\MT();
$mt->init(1234);     // mt_srand(1234);
$mt->int31();        // mt_rand();

// Breaks on huge ranges (i.e. PHP_INT_MIN, PHP_INT_MAX)
// PHP also breaks on huge ranges, but breaks differently.
$mt->rand(min, max); // mt_rand(min, max);