Beispiel #1
0
 public static function growTree(Level $level, Vector3 $pos, Random $random, $type = 0)
 {
     switch ($type & 0x3) {
         case SaplingBlock::SPRUCE:
             if ($random->nextRange(0, 1) === 1) {
                 $tree = new SpruceTreeObject();
             } else {
                 $tree = new PineTreeObject();
             }
             break;
         case SaplingBlock::BIRCH:
             $tree = new SmallTreeObject();
             $tree->type = SaplingBlock::BIRCH;
             break;
         case SaplingBlock::JUNGLE:
             $tree = new SmallTreeObject();
             $tree->type = SaplingBlock::JUNGLE;
             break;
         default:
         case SaplingBlock::OAK:
             /*if($random->nextRange(0, 9) === 0){
             			$tree = new BigTreeObject();
             		}else{*/
             $tree = new SmallTreeObject();
             //}
             break;
     }
     if ($tree->canPlaceObject($level, $pos, $random)) {
         $tree->placeObject($level, $pos, $random);
     }
 }
Beispiel #2
0
 public function random(array $generators, callable $assertion)
 {
     $shrinker = new Random($generators, $assertion);
     if ($this->options['timeLimit'] !== null) {
         $shrinker->setTimeLimit(FixedTimeLimit::realTime($this->options['timeLimit']));
     }
     return $shrinker;
 }
Beispiel #3
0
 /**
  * Generates a random number and returns a boolean representing whether it is within a given percentile.
  * For example: inPercentile(0.1) is equivalent to rand(1, 1000) == 1.
  *
  * @param float $perc The percentile to evaluate, can also be < 1.
  * @return boolean
  */
 public function inPercentile($perc)
 {
     if ($this->nextRandomNumber >= 0 && $this->nextRandomNumber <= 100 && $perc >= 0 && $perc <= 100) {
         $rand = $this->nextRandomNumber;
         $this->nextRandomNumber = -1;
         return $rand <= $perc;
     }
     return $this->realRandom->inPercentile($perc);
 }
 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, $this->waterOdd) === 0) {
         $v = new Vector3($random->nextRange($chunkX << 4, ($chunkX << 4) + 16), $random->nextRange(0, 128), $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16));
         $pond = new PondObject($random, new WaterBlock());
         if ($pond->canPlaceObject($level, $v)) {
             $pond->placeObject($level, $v);
         }
     }
 }
 public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10)
 {
     $arr = array(BlockAPI::get(DANDELION, 0), BlockAPI::get(CYAN_FLOWER, 0), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1));
     $arrC = count($arr) - 1;
     for ($c = 0; $c < $count; ++$c) {
         $x = $random->nextRange($pos->x - $radius, $pos->x + $radius);
         $z = $random->nextRange($pos->z - $radius, $pos->z + $radius);
         if ($level->level->getBlockID($x, $pos->y + 1, $z) === AIR and $level->level->getBlockID($x, $pos->y, $z) === GRASS) {
             $t = $arr[$random->nextRange(0, $arrC)];
             $level->setBlockRaw(new Vector3($x, $pos->y + 1, $z), $t);
         }
     }
 }
 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     foreach ($this->oreTypes as $type) {
         $ore = new OreObject($random, $type);
         for ($i = 0; $i < $ore->type->clusterCount; ++$i) {
             $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
             $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
             $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
             if ($ore->canPlaceObject($level, $x, $y, $z)) {
                 $ore->placeObject($level, new Vector3($x, $y, $z));
             }
         }
     }
 }
Beispiel #7
0
 public function executeDelete_confirm()
 {
     $token = Random::string(32);
     mfwSession::set(self::SESKEY_TOKEN, $token);
     $parma = array('token' => $token);
     return $this->build($parma);
 }
Beispiel #8
0
 public function actionIndex()
 {
     $newsList = array();
     $newsList = Random::getRandList();
     require_once ROOT . '/views/news/index.php';
     return true;
 }
	/**
	 *	@interface ContextService
	**/
	public function getContext($model){
		$conn = $model['conn'];
		$stgname = $conn->escape($model['stgname']);
		$filename = $conn->escape($model['filename']);
		$mime = $conn->escape($model['mime']);
		$owner = $model['owner'];
		$access = $model['access'];
		$group = $model['group'];
		$dirid = $conn->escape($model['dirid']);
		
		$stgid = Random::getString(128); 
		$ts = Time::getTime();
		
		$query = "insert into storages (stgid, stgname, filename, mime, owner, access, group, ctime, atime, mtime, dirid) values ('$stgid', '$stgname', '$filename', '$mime', $owner, $access, $group, $ts, $ts, $ts, '$dirid')";
		$result = $conn->getResult($query);
		
		if($result === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database @getContext/storage.create';
			return $model;
		}
		
		$model['valid'] = true;
		$model['stgid'] = $stgid;
		return $model;
	}
Beispiel #10
0
 /**
  * 通过邮箱找回密码
  * @method POST_emailAction
  * @author NewFuture
  */
 public function POST_emailAction()
 {
     $response['status'] = 0;
     if (!Input::post('email', $email, 'email')) {
         $response['info'] = '邮箱格式有误或者不支持!';
     } elseif (!Input::post('number', $number, 'card')) {
         $response['info'] = '学号格式有误!';
     } elseif (!Safe::checkTry('pwd_email_' . $number)) {
         $response['info'] = '尝试次数过多,临时封禁!';
     } elseif (!($user = UserModel::where('number', $number)->field('id,name,email')->find())) {
         $response['info'] = '尚未注册,或者学号错误';
     } elseif (empty($user['email'])) {
         $response['info'] = '未绑定邮箱,或者学号错误';
     } elseif (Encrypt::decryptEmail($user['email']) != $email) {
         $response['info'] = '绑定邮箱不一致,或者邮箱错误';
     } elseif (!Mail::findPwd($email, $code = Random::code(6), $user['name'])) {
         $response['info'] = '邮件发送出错,请联系我们!';
     } else {
         /*发送成功*/
         $findPwd = ['id' => $user['id'], 'number' => $number, 'code' => strtoupper($code)];
         Session::set('find_info', $findPwd);
         Safe::del('pwd_email_' . $number);
         $response['status'] = 1;
         $response['info'] = '找回验证码已发送到' . $email;
     }
     $this->response = $response;
 }
Beispiel #11
0
		public function addSession($mysql, $uid) {
		
		$time = Time::getTime();
		$session= new Session;
		$random = Random::getString(32);
		$expiry = $time + 30*24*60*60;
		$session->read($uid,$time,$expiry);
			switch($session->insert($mysql, $random)) {
				case Session::DATABASE_ERROR :
				{
					echo "<p>A Database error has occured.</p>";
					return;
				}
				case Session::INVALID_DATA :
				{
					echo "<p>Invalid operation requested.</p>";
					return;
				}
				case Session::INSERT_SUCCESS : 
				{
					
					return $random;
				}
				default :
					break;
			}
	}
	/**
	 *	@interface ContextService
	**/
	public function getContext($model){
		$conn = $model['conn'];
		$uid = $model['uid'];
		$interval = $model['interval'];

		$sessionid = Random::getString(32); 
		$ts = Time::getTime();
		$ts_exp = $ts + $interval;
		
		$query = "delete from sessions where expiry < $ts;";
		$conn->getResult($query, true);
		
		$query = "insert into sessions values('$sessionid', $uid, $ts, $ts_exp);";
		$result = $conn->getResult($query, true);
		
		if($result === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database @getContext/session.create';
			return $model;
		}
		
		$model['valid'] = true;
		$model['sessionid'] = $sessionid;

		return $model;
	}
Beispiel #13
0
 /**
  * Generates an RFC 4122-compliant version 4 UUID.
  *
  * @return string The string representation of an RFC 4122-compliant, version 4 UUID.
  * @link http://www.ietf.org/rfc/rfc4122.txt RFC 4122: UUID URN Namespace
  */
 public static function generate()
 {
     $uuid = Random::GenerateBytes(16);
     $uuid[6] = chr(ord($uuid[6]) & static::UUID_CLEAR_VER | static::UUID_VERSION_4);
     $uuid[8] = chr(ord($uuid[8]) & static::UUID_CLEAR_VAR | static::UUID_VAR_RFC);
     return join('-', array(bin2hex(substr($uuid, 0, 4)), bin2hex(substr($uuid, 4, 2)), bin2hex(substr($uuid, 6, 2)), bin2hex(substr($uuid, 8, 2)), bin2hex(substr($uuid, 10, 6))));
 }
	public function getContext($model){
		$conn = $model['conn'];
		$username = $conn->escape($model['username']);
		$email = $conn->escape($model['email']);
		$subject = $model['subject'];
		$message = $model['message'];
		
		//$newusername = Random::getString(8);
		$password = Random::getString(16);
		$result = $conn->getResult("update users set password=MD5('$username$password') where username='******' and email='$email';", true);
		
		if($result === false || $result != 1){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database';
			return $model;
		}
		
		$message = str_replace('{username}', $username, $message);
		$message = str_replace('{password}', $password, $message);
		
		$sent = Mail::send($email, $subject, $message);
		
		if($sent === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Sending Mail';
			return $model;
		}
		
		$model['valid'] = true;
		$model['sent'] = $sent;
		return $model;
	}
Beispiel #15
0
 public function create_user($userdata)
 {
     $password = \Arr::get($userdata, 'password', null);
     $email = \Arr::get($userdata, 'email', null);
     if (is_null($password) || is_null($email)) {
         Logger::instance()->log_log_in_attempt(Model_Log_In_Attempt::$ATTEMPT_BAD_CRIDENTIALS, $email);
         throw new LogInFailed(\Lang::get('ethanol.errors.loginInvalid'));
     }
     $user = Auth_Driver::get_core_user($email);
     $security = new Model_User_Security();
     //Generate a salt
     $security->salt = Hasher::instance()->hash(\Date::time(), Random::instance()->random());
     $security->password = Hasher::instance()->hash($password, $security->salt);
     if (\Config::get('ethanol.activate_emails', false)) {
         $keyLength = \Config::get('ethanol.activation_key_length');
         $security->activation_hash = Random::instance()->random($keyLength);
         $user->activated = 0;
         //Send email
         \Package::load('email');
         //Build an array of data that can be passed to the email template
         $emailData = array('email' => $user->email, 'activation_path' => \Str::tr(\Config::get('ethanol.activation_path'), array('key' => $security->activation_hash)));
         $email = \Email::forge()->from(\Config::get('ethanol.activation_email_from'))->to($user->email, $user->username)->subject(\Config::get('ethanol.activation_email_subject'))->html_body(\View::forge('ethanol/activation_email', $emailData))->send();
     } else {
         $user->activated = 1;
         $security->activation_hash = '';
     }
     $user->security = $security;
     $user->save();
     $user->clean_security();
     return $user;
 }
Beispiel #16
0
 /**
  * 通过邮箱找回密码
  * @method POST_emailAction
  * @author NewFuture
  */
 public function POST_emailAction()
 {
     $response['status'] = 0;
     if (!Input::post('email', $email, 'email')) {
         $response['info'] = '邮箱格式有误或者不支持!';
     } elseif (!Input::post('account', $account, Config::get('regex.account'))) {
         $response['info'] = '学号格式有误!';
     } elseif (!Safe::checkTry('pwd_email_' . $account)) {
         $response['info'] = '尝试次数过多,临时封禁!';
     } elseif (!($Printer = PrinterModel::where('account', $account)->field('id,email')->find())) {
         $response['info'] = '尚未注册,或者账号错误';
     } elseif (empty($Printer['email'])) {
         $response['info'] = '未绑定邮箱,或邮箱不存在';
     } elseif ($Printer['email'] != $email) {
         $response['info'] = '绑定邮箱不一致,或者邮箱错误';
     } elseif (!Mail::findPwd($email, $code = Random::code(6))) {
         $response['info'] = '邮件发送出错,请联系我们!';
     } else {
         /*发送成功*/
         $find = ['id' => $user['id'], 'account' => $account, 'code' => strtoupper($code)];
         Session::set('find_info_p', $find);
         Safe::del('pwd_email_' . $account);
         $response['status'] = 1;
         $response['info'] = '验证邮件已发送!';
     }
     $this->response = $response;
 }
 public static function get()
 {
     if (!isset(self::$rand_seeder)) {
         //if ((PHP_SAPI == 'cli') or defined('STDIN')) {
         if (IS_CLI) {
             // CodeIgniter specific implementation.
             self::$rand_seeder = Random::int(0, 2147483647);
         } else {
             //if (function_exists('get_instance')) {
             // CodeIgniter specific implementation.
             $ci = get_instance();
             $ci->load->library('session');
             $session_data = $ci->session->userdata('rand_seeder');
             if (!is_null($session_data)) {
                 self::$rand_seeder = $session_data;
             } else {
                 self::$rand_seeder = Random::int(0, 2147483647);
                 $ci->session->set_userdata('rand_seeder', self::$rand_seeder);
             }
             //} else {
             //    if (isset($_SESSION['rand_seeder'])) {
             //        self::$rand_seeder = $_SESSION['rand_seeder'];
             //    } else {
             //        self::$rand_seeder = rand();
             //        $_SESSION['rand_seeder'] = self::$rand_seeder;
             //    }
             //}
         }
     }
     return self::$rand_seeder;
 }
 function add_to_gallery()
 {
     $gallery_peer = new GalleryPeer();
     $gallery = $gallery_peer->find_by_id(Params::get("id_gallery"));
     $collection_peer = new GalleryCollectionPeer();
     $gallery_collection = $collection_peer->find_by_id($gallery->id_gallery_collection);
     $full_folder_path = GalleryCollectionController::GALLERY_COLLECTION_ROOT_DIR . $gallery_collection->folder . "/" . $gallery->folder;
     if (Upload::isUploadSuccessful("file")) {
         $filename = Random::newHexString() . "_" . Upload::getRealFilename("file");
         $gallery_dir = new Dir($full_folder_path);
         $uploaded_img = Upload::saveTo("file", $gallery_dir, $filename);
         if (isset(Config::instance()->GALLERY_RESIZE_BY_WIDTH)) {
             image_w($uploaded_img->getPath(), Config::instance()->GALLERY_RESIZE_BY_WIDTH);
         } else {
             if (isset(Config::instance()->GALLERY_RESIZE_BY_HEIGHT)) {
                 image_h($uploaded_img->getPath(), Config::instance()->GALLERY_RESIZE_BY_HEIGHT);
             }
         }
         $peer = new GalleryImagePeer();
         $do = $peer->new_do();
         $peer->setupByParams($do);
         $do->image_name = $filename;
         $peer->save($do);
         return Redirect::success();
     } else {
         Flash::error(Upload::getUploadError("file"));
         return Redirect::failure();
     }
 }
Beispiel #19
0
 /**
  * Random strings should be different
  */
 public function testUniqueString()
 {
     $value1 = Random::getUniqueString();
     $value2 = Random::getUniqueString();
     $this->assertInternalType('string', $value1);
     $this->assertInternalType('string', $value2);
     $this->assertNotEquals($value1, $value2);
 }
Beispiel #20
0
 protected function makeToken()
 {
     $pkg_id = $this->package->getId();
     $token = Random::string(32);
     // tokenは60秒有効
     mfwMemcache::set(self::TOKEN_KEY_PREFIX . $token, $pkg_id, 60);
     return $token;
 }
Beispiel #21
0
 public function __construct($node, $parent)
 {
     parent::__construct($node, $parent);
     self::$possible_attributes = array_merge(parent::$possible_attributes, self::$possible_attributes);
     self::$required_attributes = array_merge(parent::$required_attributes, self::$required_attributes);
     self::$possible_children = array_merge(parent::$possible_children, self::$possible_children);
     self::$required_children = array_merge(parent::$required_children, self::$required_children);
 }
Beispiel #22
0
Datei: Guid.php Projekt: ud223/yj
 public function toString()
 {
     $address = NetAddress::getLocalHost();
     $this->valueBeforeMD5 = $address->toString() . ':' . System::currentTimeMills() . ':' . Random::nextLong();
     $this->valueAfterMD5 = md5($this->valueBeforeMD5);
     $raw = strtoupper($this->valueAfterMD5);
     return substr($raw, 0, 8) . '-' . substr($raw, 8, 4) . '-' . substr($raw, 16, 4) . '-' . substr($raw, 20);
 }
Beispiel #23
0
 public static function generate($seed, $count = 500, $min = 0, $max = 100)
 {
     $sequence = [];
     self::$seed = abs(crc32($seed)) % 999999 + 1;
     for ($i = 1; $i <= $count; $i++) {
         $sequence[] = self::numgen($min, $max);
     }
     return $sequence;
 }
Beispiel #24
0
 /**
  * Generates a facebook login page using the facebook template
  * 
  * @return string
  */
 public function get_form()
 {
     $csrf_key = Random::instance()->random();
     Session::instance()->get_instance()->set('ethanol.driver.facebook.csrf', $csrf_key);
     $redirect_url = urlencode(parent::get_login_controller_path('facebook'));
     $app_id = \Config::get('ethanol.facebook.app_id');
     $login_url = "https://www.facebook.com/dialog/oauth?client_id={$app_id}&redirect_uri={$redirect_url}&state={$csrf_key}&scope=email";
     return \View::forge('ethanol/driver/facebook_login')->set('login_url', $login_url)->render();
 }
Beispiel #25
0
 public static function generateRandomWithPotential($first, $second)
 {
     $max = $first + $second;
     $random = rand(0, $max);
     if ($first > $second) {
         return Random::getWinner($second, $first, $random);
     } else {
         return Random::getWinner($first, $second, $random);
     }
 }
 public function placeObject(Level $level, Vector3 $pos, Random $random)
 {
     // The base dirt block
     $dirtpos = new Vector3($pos->x, $pos->y - 1, $pos->z);
     $level->setBlockRaw($dirtpos, new DirtBlock());
     // Adjust the tree trunk's height randomly
     //    plot [-14:11] int( x / 8 ) + 5
     //    - min=4 (all leaves are 4 tall, some trunk must show)
     //    - max=6 (top leaves are within ground-level whacking range
     //             on all small trees)
     $heightPre = $random->nextRange(-14, 11);
     $this->trunkHeight = intval($heightPre / 8) + 5;
     // Adjust the starting leaf density using the trunk height as a
     // starting position (tall trees with skimpy leaves don't look
     // too good)
     $leafPre = $random->nextRange($this->trunkHeight, 10) / 20;
     // (TODO: seed may apply)
     // Now build the tree (from the top down)
     $leaflevel = 0;
     for ($yy = $this->trunkHeight + 1; $yy >= 0; --$yy) {
         if ($leaflevel < self::$leavesHeight) {
             // The size is a slight variation on the trunkheight
             $radius = self::$leafRadii[$leaflevel] + $leafPre;
             $bRadius = 3;
             for ($xx = -$bRadius; $xx <= $bRadius; ++$xx) {
                 for ($zz = -$bRadius; $zz <= $bRadius; ++$zz) {
                     if (sqrt($xx * $xx + $zz * $zz) <= $radius) {
                         $leafpos = new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz);
                         $level->setBlockRaw($leafpos, new LeavesBlock($this->type));
                     }
                 }
             }
             $leaflevel++;
         }
         // Place the trunk last
         if ($leaflevel > 1) {
             $trunkpos = new Vector3($pos->x, $pos->y + $yy, $pos->z);
             $level->setBlockRaw($trunkpos, new WoodBlock($this->type));
         }
     }
 }
 public static function post()
 {
     $page = new Page();
     $page->data['title'] = 'Wachtwoord resetten';
     $errMsgs = ResetPasswordViewValidator::validate($_POST);
     if (empty($errMsgs)) {
         try {
             //Get the user's password salt and calculate password hash
             $passwordSalt = UserDB::getPasswordSaltByEmail($_POST['email']);
             $newPassword = Random::getPassword();
             $newPasswordHash = hash_pbkdf2('sha256', $newPassword, $passwordSalt, SecurityConfig::N_PASSWORD_HASH_ITERATIONS);
             //Get user from database and reset password.
             $user = UserDB::getBasicUserByEmail($_POST['email']);
             UserDB::resetPassword($_POST['email'], $newPasswordHash);
             //Show success message
             $page->data['ResetSuccessfulView']['redirectUrl'] = 'login';
             $page->addView('resetPassword/ResetSuccessfulView');
             //Send email with password
             $failedEmails = Email::sendEmails('ResetPassword.html', 'JH De Stip - Wachtwoord reset', EmailConfig::FROM_ADDRESS, [$user], array($user->userId => array('newPassword' => $newPassword)));
             //If failedEmails is not empty the mail was not sent
             if (!empty($failedEmails)) {
                 $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan e-mail met nieuwe wachtwoord niet verzenden.';
                 $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
             }
         } catch (UserDBException $ex) {
             $page->data['ResetPasswordView']['reset_password_formAction'] = $_SERVER['REQUEST_URI'];
             $page->data['ResetPasswordView']['email'] = $_POST['email'];
             $page->data['ResetPasswordView']['errMsgs'] = ResetPasswordViewValidator::initErrMsgs();
             if ($ex->getCode() == UserDBException::NOUSERFOREMAIL) {
                 $page->data['ResetPasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="reset_password_form_error_message">Er is geen gebruiker met dit e-mailadres.</h2>';
             } else {
                 $page->data['ResetPasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="reset_password_form_error_message">Kan wachtwoord niet resetten, probeer het opnieuw.</h2>';
             }
             $page->addView('resetPassword/ResetPasswordView');
         } catch (EmailException $ex) {
             $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan e-mail met nieuwe wachtwoord niet verzenden.';
             $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
         } catch (Exception $ex) {
             $page->data['ResetPasswordView']['reset_password_formAction'] = $_SERVER['REQUEST_URI'];
             $page->data['ResetPasswordView']['email'] = $_POST['email'];
             $page->data['ResetPasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="reset_password_form_error_message">Kan wachtwoord niet resetten, probeer het opnieuw.</h2>';
             $page->addView('resetPassword/ResetPasswordView');
         }
     } else {
         $page->data['ResetPasswordView']['reset_password_formAction'] = $_SERVER['REQUEST_URI'];
         $page->data['ResetPasswordView']['email'] = $_POST['email'];
         $page->data['ResetPasswordView']['errMsgs'] = ResetPasswordViewValidator::initErrMsgs();
         $page->data['ResetPasswordView']['errMsgs'] = array_merge($page->data['ResetPasswordView']['errMsgs'], $errMsgs);
         $page->addView('resetPassword/ResetPasswordView');
     }
     $page->showWithMenu();
 }
Beispiel #28
0
 /**
  * ランダムパスワードを生成する
  *
  * @param int
  * @param array
  * @return string
  */
 public static function generate($length = 8, $chars = ['-', '_', '.', '$', '#', '%'])
 {
     if ($length < 4) {
         throw new \Exception('パスワードが短すぎます');
     }
     $password = Random::string($length, $chars);
     // 強度のテスト 大文字,小文字,数字,記号の混在
     // 先頭,記号,数字不可
     if (preg_match('/[A-Z]/', $password) && preg_match('/[a-z]/', $password) && preg_match('/[0-9]/', $password) && preg_match('/^[A-Za-z]/', $password)) {
         return $password;
     }
     return self::generate($length, $chars = []);
 }
 public function __construct($random = false)
 {
     if (!$random instanceof Random) {
         $random = new Random();
     }
     $this->xCoord = $random->nextFloat() * 256;
     $this->yCoord = $random->nextFloat() * 256;
     $this->zCoord = $random->nextFloat() * 256;
     for ($i = 0; $i < 512; ++$i) {
         $this->permutations[$i] = 0;
     }
     for ($i = 0; $i < 256; ++$i) {
         $this->permutations[$i] = $i;
     }
     for ($i = 0; $i < 256; ++$i) {
         $j = $random->nextRange(0, 256 - $i) + $i;
         $k = $this->permutations[$i];
         $this->permutations[$i] = $this->permutations[$j];
         $this->permutations[$j] = $k;
         $this->permutations[$i + 256] = $this->permutations[$i];
     }
 }
Beispiel #30
0
 protected static function childIQ($gender, $father, $mother)
 {
     // // Son's IQ depends on mother's IQ
     // if ($gender == Human::MALE) {
     //     $iQ = Random::iQ($mother->getIQ(), self::IQ_INHER_VAR, self::IQ_INHER_SD);
     // // Daughter's IQ depends on father's and mother's IQ
     // } else {
     //     $averageIQ = ($father->getIQ() + $mother->getIQ()) / 2;
     //     $iQ = Random::iQ($averageIQ, self::IQ_INHER_VAR, self::IQ_INHER_SD);
     // }
     $iQ = Random::iQ($mother->getIQ(), self::IQ_INHER_VAR, self::IQ_INHER_SD);
     return $iQ;
 }