当前位置: 首页>>代码示例>>PHP>>正文


PHP Random::generate方法代码示例

本文整理汇总了PHP中Random::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::generate方法的具体用法?PHP Random::generate怎么用?PHP Random::generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Random的用法示例。


在下文中一共展示了Random::generate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($chromosome, Element $element = null)
 {
     if (is_array($chromosome)) {
         $this->chromosome = $chromosome;
     } else {
         $this->chromosome = new SplFixedArray($chromosome);
         for ($gene = 0; $gene < $chromosome; $gene++) {
             if (0.5 < Random::generate()) {
                 $this->setGene($gene, 1);
             } else {
                 $this->setGene($gene, 0);
             }
         }
     }
 }
开发者ID:alexspit,项目名称:SGA,代码行数:15,代码来源:Individual.php

示例2: mutate

 public function mutate(Population $population)
 {
     $newPopulation = new Population($population->size());
     for ($populationIndex = 0; $populationIndex < $population->size(); $populationIndex++) {
         $individual = $population->getFittestIndividual($populationIndex);
         for ($geneIndex = 0; $geneIndex < $individual->getChromosomeLength(); $geneIndex++) {
             if ($populationIndex >= $this->elitismCount) {
                 if ($this->mutationRate > Random::generate()) {
                     $newGene = 1;
                     if ($individual->getGene($geneIndex) == 1) {
                         $newGene = 0;
                     }
                     $individual->setGene($geneIndex, $newGene);
                 }
             }
         }
         $newPopulation->setIndividual($populationIndex, $individual);
     }
     return $newPopulation;
 }
开发者ID:alexspit,项目名称:SGA,代码行数:20,代码来源:GeneticAlgorithm.php

示例3: Property

$element->addProperty(new Property(6, "font-weight", ["normal", "lighter", "bold"]));
$element->addProperty(new Property(7, "letter-spacing", ["-3px", "-2px", "-1px", "0px", "1px", "2px", "3px"]));
$element->addProperty(new Property(7, "background-color", ["#1abc9c", "#16a085", "#f1c40f", "#f39c12", "#40d47e", "#27ae60", "#e67e22", "#d35400", "#3498db", "#2980b9", "#e74c3c", "#c0392b", "#9b59b6", "#8e44ad", "#ecf0f1", "#bdc3c7", "#34495e", "#2c3e50", "#95a5a6", "#7f8c8d"]));
$ga = new GeneticAlgorithm(5, 0.9, 0.1, 1);
$population = $ga->initPopulation($element);
$individuals = $population->getIndividuals();
//Printing Style
echo "<style>";
foreach ($individuals as $id => $individual) {
    echo "\n" . $ga->decode($id + 1, $individual, $element);
}
echo "</style>";
//Printing headers
foreach ($individuals as $id => $individual) {
    $id++;
    echo "Encoded: " . $individual . "<br>";
    echo "Decoded: <h1 id='individual{$id}'>This is a Title</h1>";
    echo '<input type="text" class="input_range" id="range_' . $id . '" form="form1" name="individual_' . $id . '" value="" />';
}
//TEMP:: Setting random fitness
foreach ($population->getIndividuals() as &$i) {
    $i->setFitness(Random::generate());
}
$ga->evalPopulation($population);
echo $population->getPopulationFitness() . "<br>";
$_SESSION['population'] = serialize($population);
?>


<?php 
include_once "includes/masterpage/footer.php ";
开发者ID:alexspit,项目名称:IGA_Prototype,代码行数:31,代码来源:index.php

示例4: Slim

<?php

require 'vendor/autoload.php';
require 'Random.php';
// Ukljuci debug
// ini_set('display_errors',1);
// ini_set('display_startup_errors',1);
// error_reporting(-1);
use sweelix\guid\Guid;
use Slim\Slim;
use SlimJson\Middleware;
$app = new Slim();
// Dodaj JSON midleware globalno
$app->add(new Middleware(array('json.status' => true, 'json.override_error' => true, 'json.override_notfound' => true)));
// Povezi se sa bazom
$pdo = new PDO("sqlite:db.sqlite");
$fpdo = new FluentPDO($pdo);
// API za generisanje slucajnog broja
$app->get('/match(/:id)', function ($id = '%NO-DATA%') use($app, $fpdo) {
    if ($id == '%NO-DATA%') {
        $id = Guid::v4();
    }
    $match = $fpdo->from('matches')->where('id', $id)->fetch();
    if (!$match) {
        $data = ['id' => $id, 'player1_id' => NULL, 'player2_id' => NULL, 'data' => implode(';', Random::generate($id, 500, 0, 100))];
        $query = $fpdo->insertInto('matches', $data)->execute();
        $match = $data;
    }
    $app->render(200, $match);
});
$app->run();
开发者ID:johonunu,项目名称:game-api,代码行数:31,代码来源:index.php

示例5: mutateUniform

 public function mutateUniform(Population $population, Element $element)
 {
     $newPopulation = new Population($population->size());
     for ($populationIndex = 0; $populationIndex < $population->size(); $populationIndex++) {
         $individual = $population->getFittestIndividual($populationIndex);
         $randomIndividual = new Individual($element);
         for ($geneIndex = 0; $geneIndex < $individual->getChromosomeLength(); $geneIndex++) {
             if ($populationIndex >= $this->elitismCount) {
                 if ($this->mutationRate > Random::generate()) {
                     $individual->setGene($geneIndex, $randomIndividual->getGene($geneIndex));
                 }
             }
         }
         $newPopulation->setIndividual($populationIndex, $individual);
     }
     return $newPopulation;
 }
开发者ID:alexspit,项目名称:IGA_Prototype,代码行数:17,代码来源:GeneticAlgorithm.php


注:本文中的Random::generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。