在php中从rand中排除动态数字
我正在尝试根据计算出的加密密钥构建一个映像。这纯粹是为了让我自己在PHP方面做得更好。图像应该类似于电报加密。我现在有下面的代码来计算每种颜色的方块数。我不知道的是,如何从这里开始,用这些彩色方块填满一张桌子。我可以使用rand生成坐标,但如何排除已填充的正方形 PHP在php中从rand中排除动态数字,php,Php,我正在尝试根据计算出的加密密钥构建一个映像。这纯粹是为了让我自己在PHP方面做得更好。图像应该类似于电报加密。我现在有下面的代码来计算每种颜色的方块数。我不知道的是,如何从这里开始,用这些彩色方块填满一张桌子。我可以使用rand生成坐标,但如何排除已填充的正方形 PHP //number of squares with a certain color $white = rand (0, 50); $lightblue = rand (0, 200); $whiteblue = $white +
//number of squares with a certain color
$white = rand (0, 50);
$lightblue = rand (0, 200);
$whiteblue = $white + $lightblue;
$darkblue = rand ($whiteblue, 750);
$total = '1024';
$mediumblue = $total - ($darkblue + $whiteblue);
$totalsquares = $white + $lightblue + $mediumblue + $darkblue;
//number of letters in white squares
$letters = rand(0, $white);
我对您的代码进行了一些修改,使其更易于管理。本质上,它将适当数量的彩色正方形添加到一个数组中,然后该数组被洗牌。要绘制正方形,只需遍历该数组
$squares = array();
$total = 1024;
$squares['white'] = rand (0, 50);
$squares['lightblue'] = rand (0, 200);
$whiteblue = $squares['white'] + $squares['lightblue'];
$squares['darkblue'] = rand ($whiteblue, 750);
$squares['mediumblue'] = $total - ($squares['darkblue'] + $whiteblue);
//number of letters in white squares
$squares['whiteletters'] = rand(0, $squares['white']);
$squares['white'] -= $squares['whiteletters'];
// Create array of squares
$items = array();
foreach ($squares as $key => $count) {
$items = array_merge($items, array_fill(0, $count, $key));
}
shuffle($items);
// Draw squares
$size = sqrt($total);
// <table>
for ($y = 0; $y < $size; $y++) {
// <tr>
for ($x = 0; $x < $size; $x++) {
$square = $items[$y * $size + $x];
// <td>
// draw $square
// </td>
}
// </tr>
}
// </table>
$squares=array();
$total=1024;
$squares['white']=兰特(0,50);
$squares['lightblue']=兰特(0200);
$whiteblue=$squares['white']+$squares['lightblue'];
$squares['darkblue']=兰特($whiteblue,750美元);
$squares['mediumblue']=$total-($squares['darkblue']+$whiteblue);
//白色方块中的字母数
$squares['whiteletters']=兰特(0,$squares['white']);
$squares['white']-=$squares['whitelets'];
//创建正方形阵列
$items=array();
foreach($key=>$count的正方形){
$items=array_merge($items,array_fill(0,$count,$key));
}
洗牌($项目);
//画正方形
$size=sqrt($total);
//
对于($y=0;$y<$size;$y++){
//
对于($x=0;$x<$size;$x++){
$square=$items[$y*$size+$x];
//
//抽取$square
//
}
//
}
//
非常感谢!我要建一张桌子,填满每个单元格。在您的代码中,我不知道如何绘制…@user3290485:我已经对代码进行了注释,以显示适当的HTML表标记将输出到哪里。谢谢,这是一个美丽的地方<代码>'1024'-哎哟。不要。这是一个数字。哦,没关系,那真是太愚蠢了。