次のように単純にする必要があります。
$ratio = 200/300;
$width = mt_rand(100, 250);
$height = round($width / $ratio);
いくつかの例を参照してください。
$ratio = 200/300;
echo "base aspect ratio: ", round($ratio, 2), "\n\n";
foreach(range(1,10) as $_) {
$width = mt_rand(100, 250);
$height = round($width / $ratio);
echo "http://placekitten.com/{$width}/{$height}\n";
echo "aspect ratio: ", round($width / $height, 2), "\n\n";
}
出力
base aspect ratio: 0.67
http://placekitten.com/229/344
aspect ratio: 0.67
http://placekitten.com/112/168
aspect ratio: 0.67
http://placekitten.com/241/362
aspect ratio: 0.67
http://placekitten.com/223/335
aspect ratio: 0.67
http://placekitten.com/196/294
aspect ratio: 0.67
http://placekitten.com/234/351
aspect ratio: 0.67
http://placekitten.com/116/174
aspect ratio: 0.67
http://placekitten.com/157/236
aspect ratio: 0.67
http://placekitten.com/165/248
aspect ratio: 0.67
http://placekitten.com/114/171
aspect ratio: 0.67