note 110798 added to function.mt-rand
| From: | justinba1010 at gmail dot com | Date: | Sun, 09 Dec 2012 23:39:53 +0000 |
| Subject: | note 110798 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192433@lists.php.net to get a copy of this message | ||
<?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.
*/
?>
----
Server IP: 69.147.83.199
Probable Submitter: 72.52.91.2 (proxied: 68.192.201.174)
----
Manual Page -- http://php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/110798
Del: integrated -- https://master.php.net/note/delete/110798/integrated
Del: useless -- https://master.php.net/note/delete/110798/useless
Del: bad code -- https://master.php.net/note/delete/110798/bad+code
Del: spam -- https://master.php.net/note/delete/110798/spam
Del: non-english -- https://master.php.net/note/delete/110798/non-english
Del: in docs -- https://master.php.net/note/delete/110798/in+docs
Del: other reasons-- https://master.php.net/note/delete/110798
Reject -- https://master.php.net/note/reject/110798
Search -- https://master.php.net/manage/user-notes.php