this is certainly a very complex problem.

I think a simple solution would be to create an array with multiple numbers. Something like below

$x[] = 1;
$x[] = 2;
$x[] = 2;
$x[] = 2;

Simple example so basically you can increase the chances of certain numbers that appear.

so if you want 2 to appear more then 1 then 3 out of 4 times. This is a small scale example. This would be using rand(0, 4-1)