Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6067658
RandomRange.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
RandomRange.php
View Options
<?php
namespace
Eris\Random
;
/**
* @return RandomRange
*/
function
purePhpMtRand
()
{
return
new
RandomRange
(
new
MersenneTwister
());
}
// TODO: Extract Interface
class
RandomRange
{
private
$source
;
public
function
__construct
(
$source
)
{
$this
->
source
=
$source
;
}
/**
* @return void
*/
public
function
seed
(
$seed
)
{
$this
->
source
->
seed
(
$seed
);
}
/**
* Return a random number.
* If $lower and $upper are specified, the number will fall into their
* inclusive range.
* Otherwise the number from the source will be directly returned.
*
* @param integer|null $lower
* @param integer|null $upper
* @return integer
*/
public
function
rand
(
$lower
=
null
,
$upper
=
null
)
{
if
(
$lower
===
null
&&
$upper
===
null
)
{
return
$this
->
source
->
extractNumber
();
}
if
(
$lower
>
$upper
)
{
list
(
$lower
,
$upper
)
=
[
$upper
,
$lower
];
}
$delta
=
$upper
-
$lower
;
$divisor
=
(
$this
->
source
->
max
())
/
(
$delta
+
1
);
do
{
$retval
=
(
int
)
floor
(
$this
->
source
->
extractNumber
()
/
$divisor
);
}
while
(
$retval
>
$delta
);
return
$retval
+
$lower
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 5 2026, 05:19 (6 w, 10 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0d/30/8f522ac8a87027818ca13b564ea0
Default Alt Text
RandomRange.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment