显示两个循环的随机和交叉循环


To show looping for two looping in random and cross

我有循环问题,我想显示回放随机到循环

代码:

            for ($i=0; $i <= 10; $i++) { 
            $result = $i;
            echo "$result";
            echo "<br>";
            }
    //----------------------------------------------
            echo "<hr width='100%'>";
    //----------------------------------------------
            $s=$result;
            $c=$result;
            $test=array_fill($s, $c, 0);
            $ts=microtime(true);
            for ($i=0; $i <= 10; $i++) { 
                $selection1=mt_rand($s, $c);
                $selection2=mt_rand($s, $c);
                echo "$selection1 and $selection1";
                echo "<br>";
            }

我想要结果:示例结果

随机之后我想要交叉循环示例结果

#including completion of a genetic algorithm  

mt_rand返回您提供的第一个值和最后一个值之间的值。在您的代码中,当$s和$c都设置为10时,您将调用mt_rand($s, $c),因此它们将始终返回10。

我很难理解你想要什么,所以让我们看看你的代码,看看发生了什么。

        for ($i=0; $i <= 10; $i++) { 
            $result = $i;
            echo "$result";
            echo "<br>";
        }

在上面,我们在0和10之间循环,每次都将循环编号存储为$result

//----------------------------------------------
        echo "<hr width='100%'>";
//----------------------------------------------
        $s=$result;
        $c=$result;
        $test=array_fill($s, $c, 0);
        $ts=microtime(true);

我们的循环已经结束,我们继续前进。这段代码只执行一次。由于$result在循环结束时是10,因此$s$c将始终设置为10。

        for ($i=0; $i <= 10; $i++) { 
            $selection1=mt_rand($s, $c);
            $selection2=mt_rand($s, $c);
            echo "$selection1 and $selection1";
            echo "<br>";
        }

现在我们将再次在0和10之间循环。mt_rand()将始终返回$s$c之间的值,该值将始终设置为1010,因此始终为10。我们只想回10 and 10 10次。

我不确定你在找什么,所以我就把这个解释留在那里。