mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
arrow physics kinda changed(still doesnt normally work)
This commit is contained in:
parent
577e00378e
commit
f9a11b5eba
4 changed files with 61 additions and 47 deletions
|
|
@ -23,6 +23,8 @@
|
|||
//Unsecure, not used for "Real Randomness"
|
||||
class Random{
|
||||
private $x, $y, $z, $w;
|
||||
private $haveNextNextGaussian = false;
|
||||
private $nextNextGaussian = 0;
|
||||
public function __construct($seed = false){
|
||||
$this->setSeed($seed);
|
||||
}
|
||||
|
|
@ -42,7 +44,23 @@ class Random{
|
|||
$this->state = $state;
|
||||
$this->i = $this->j = 0;
|
||||
}
|
||||
|
||||
public function nextGaussian(){
|
||||
if ($this->haveNextNextGaussian) {
|
||||
$this->haveNextNextGaussian = false;
|
||||
return $this->nextNextGaussian;
|
||||
} else {
|
||||
$v1 = $v2 = $s = null;
|
||||
do {
|
||||
$v1 = 2 * $this->nextFloat() - 1; // between -1.0 and 1.0
|
||||
$v2 = 2 * $this->nextFloat() - 1; // between -1.0 and 1.0
|
||||
$s = $v1 * $v1 + $v2 * $v2;
|
||||
} while ($s >= 1 || $s == 0);
|
||||
$multiplier = sqrt(-2 * log($s)/$s);
|
||||
$nextNextGaussian = $v2 * $multiplier;
|
||||
$haveNextNextGaussian = true;
|
||||
return $v1 * $multiplier;
|
||||
}
|
||||
}
|
||||
public function nextInt(){
|
||||
return Utils::readInt($this->nextBytes(4)) & 0x7FFFFFFF;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue