note 110798 deleted from function.mt-rand by aharvey
| From: | aharvey@php.net | Date: | Mon, 10 Dec 2012 00:52:40 +0000 |
| Subject: | note 110798 deleted from function.mt-rand by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192436@lists.php.net to get a copy of this message | ||
Note Submitter: justinba1010 at gmail dot com
----
<?php
/* @Author: Justin Baum
** @Date: 12/9/12 - m/d/yr
** @Purpose: To create a better random number for numbers above 2^32
*/
/* If a number higher then 2^32 is needed
** Then I think this should be proposed
** This is because the mt_rand(0,2^64) is biased to even
** numbers.
*/
/* This incorporates the mt_rand, Mersenne twister, and a few
** exponents to insure there is more odd numbers in the
** equation, this is just a theory and I hope others will look into
** it.
*/
public function mt_rand_64($min, $max) {
//Get the random seed
$rand = mt_rand();
//Get the random exponent
$rand_exponent1 = mt_rand(900,1100);
$rand2_exponent1 = $rand_exponent - 50;
$rand2_exponent2 = $rand_exponent + 50;
$rand_exponent2 = mt_rand($rand2_exponent1, $rand2_exponent2);
$rand_exponent = $rand_exponent1 / $rand_exponent2;
//Get the exponential of random
$rand = $rand ^ $rand_exponent;
//Get the differential
$difference = $max - $min;
//Get the actual random number
$random_number = $rand % $difference;
$random_number += $min;
RETURN $random_number;
}
/* I hope this is looked into, and this is just my solution to it,
** It is crude, and a better one should be used.
** Thank you.
*/
?>