mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
New Level Generator API & Support for MC Superflat Presets
This commit is contained in:
parent
edb93d6312
commit
5ea6052a8a
8 changed files with 809 additions and 440 deletions
61
src/utils/Random.php
Normal file
61
src/utils/Random.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ PocketMine \
|
||||
/ MP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//Unsecure, not used for "Real Randomness"
|
||||
class Random{
|
||||
private $random;
|
||||
public function __construct($seed = false){
|
||||
$this->random = new mersenne_twister\twister(0);
|
||||
$this->setSeed($seed);
|
||||
}
|
||||
|
||||
public function setSeed($seed = false){
|
||||
$this->random->init_with_integer($seed !== false ? (int) $seed:Utils::readInt(Utils::getRandomBytes(4, false)));
|
||||
}
|
||||
|
||||
public function nextInt(){
|
||||
return $this->random->int32();
|
||||
}
|
||||
|
||||
public function nextFloat(){
|
||||
return $this->random->real_closed();
|
||||
}
|
||||
|
||||
public function nextBytes($byteCount){
|
||||
$bytes = "";
|
||||
for($i = 0; $i < $byteCount; ++$i){
|
||||
$bytes .= chr($this->random->rangeint(0, 0xFF));
|
||||
}
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
public function nextBoolean(){
|
||||
return $this->random->rangeint(0, 1) === 1;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue