mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
unfinished vanilla generator
This commit is contained in:
parent
75ddac1a73
commit
8e241171a3
26 changed files with 1156 additions and 28 deletions
|
|
@ -19,7 +19,9 @@
|
|||
Only the class `twister' is part of the API; everything else is private.
|
||||
|
||||
http://kingfisher.nfshost.com/sw/twister/
|
||||
|
||||
|
||||
|
||||
Who made such a weird names? - GameHerobrine
|
||||
*/
|
||||
const N = 624;
|
||||
const M = 397;
|
||||
|
|
@ -41,7 +43,7 @@ $val = MASK31 | (MASK31 << 1);
|
|||
define("MASK32", $val);
|
||||
|
||||
|
||||
class MersenneTwister{ //Does it even used? //rename back if any problems will be spotted
|
||||
class MersenneTwister{
|
||||
|
||||
const N = N;
|
||||
# the class constant is not used anywhere in this namespace,
|
||||
|
|
@ -202,7 +204,7 @@ class MersenneTwister{ //Does it even used? //rename back if any problems will b
|
|||
|
||||
return $y;
|
||||
}
|
||||
|
||||
|
||||
/* generates a random number on [0,1]-real-interval */
|
||||
|
||||
function real_closed(){
|
||||
|
|
@ -330,6 +332,19 @@ class MersenneTwister{ //Does it even used? //rename back if any problems will b
|
|||
($this->int32() & MASK26)) *
|
||||
(1.0 / 9007199254740992.0);
|
||||
}
|
||||
|
||||
function nextInt($bound = null){
|
||||
return $bound == null ? ($this->int32() >> 1) : ($this->int32() % $bound);
|
||||
}
|
||||
|
||||
function nextFloat(){
|
||||
return $this->int32() * 2.3283064365386963E-010;
|
||||
}
|
||||
|
||||
function setSeed($seed){
|
||||
$this->init_with_integer($seed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function signed2unsigned($signed_integer){
|
||||
|
|
|
|||
|
|
@ -44,6 +44,29 @@ class Utils{
|
|||
$angle = fmod($angle, 360);
|
||||
return $angle < 0 ? $angle + 360 : $angle;
|
||||
}
|
||||
|
||||
public static function getSeedNumeric($seed){
|
||||
if($seed === "") return false;
|
||||
else if(is_int($seed)) return (int)$seed;
|
||||
else{
|
||||
$i = 0;
|
||||
for($j = 0; $j < strlen($seed); ++$j){
|
||||
$i = $i * 31 + ord($seed[$j]);
|
||||
}
|
||||
return (int)$i;
|
||||
}
|
||||
}
|
||||
|
||||
public static function sint32($r){
|
||||
$r &= 0xFFFFFFFF;
|
||||
if ($r & 0x80000000)
|
||||
{
|
||||
$r &= ~0x80000000;
|
||||
return -2147483648 + $r;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
public static function wrapAngleTo180($angle)
|
||||
{
|
||||
$angle = fmod($angle+180, 360);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue