doushun1870 2016-05-14 08:28
浏览 56

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

i have looping problem, i want To show replay random To looping

Code:

            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>";
            }

i want result: example result

and after random i want cross looping Example result

#including completion of a genetic algorithm  
</div>
  • 写回答

1条回答 默认 最新

  • douerqu2319 2016-05-15 02:50
    关注

    mt_rand returns a value between the first and last values you provide. In your code, you are calling mt_rand($s, $c) when $s and $c are both set to 10, so they will always return 10.

    I'm having trouble understanding what you want, so let's take a look at your code and see what's going on.

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

    Above we're looping between 0 and 10, each time around storing our loop number as $result.

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

    Our loop has finished and we're moving on. This code is executed once. Since $result was 10 at the end of the loop, $s and $c will always be set to 10.

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

    We're now going to loop between 0 and 10 again. mt_rand() will always return a value between $s and $c, which will always be set to 10 and 10, so will always be 10. We're just going to echo 10 and 10 10 times.

    I'm unsure what you're looking for so I'll just leave that explanation there.

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)