Creating a random number, but with a twist

I need to create a random number.

But the twist is that% of lower numbers should be greater than higher.

For instance.

rand> 1 to 100

13 , 15 , 12 , 16 , 87, 15 , 27 , 12 , 1 , 12 , 98, 12 , 53, 12 , 14 ....

Bold integers will be returned from the range 1-100.

Mathematics should be like this: rand = a number lower than max/2

Hope you guys can help.

Ps, How would a matrix get into this? im not superior in math :(


The answer to abs seems to be this.

$up = $down = 0;
while(true)
{
   if(abs((rand()%150)-50) < 50)
   {
      $up++;
   }else
   {
      $down++;
   }
   if( ($up + $down) == 500){ break;}
}

echo $up . '/' . $down;
+3
3

n = abs((rand()%150)-50)
+5
$x = rand(0,1) ? rand(1,100) : rand(1,50);

: rand (0,1) . 1..50, 1..100 . 1,100 1,50, 100% , 1 2 .

, 99 , 1..20 , rand(1,rand(1,100)).

+3
$rand = (rand() * rand()) / (getrandmax() * getrandmax());

0 1 . , .

0

Source: https://habr.com/ru/post/1752882/


All Articles