user14541933
user14541933

Reputation:

mt_rand math numbers

I want to create an application that shows multiplication, addition, subtraction and division with 2 random numbers. I made a function that shows random numbers:

function Numbers() {
    echo(mt_rand() . "<br>");
    echo(mt_rand() . "<br>");
    echo(mt_rand(1,10));

}
  
Numbers();

Can someone explain to me how I can make it go +/- and x each other?

I now changed my code to this:

function Numbers() {
    $Number1= echo(mt_rand() . "<br>");
    $Number2= echo(mt_rand() . "<br>");
   
    $Number1 + $Number2;
    $Number1 - $Number2;
    $Number1 / $Number2;

}
  
Numbers();

Upvotes: 0

Views: 89

Answers (2)

user13977214
user13977214

Reputation: 46

function printRnd()
{
    $a_ = rand(1,10);
    $b_ = rand(1,10);
    echo "a={$a_}, b={$b_}<br><br>";
    $plus_ = $a_+$b_;
    $minus_ = $a_-$b_;
    $multi_ = $a_*$b_;
    $divid_ = $a_/$b_;
    echo "a+b={$plus_}<br>";
    echo "a-b={$minus_}<br>";
    echo "a*b={$multi_}<br>";
    echo "a/b={$divid_}<br>";
}
printRnd();

Upvotes: 1

Zoli Szab&#243;
Zoli Szab&#243;

Reputation: 4534

Here's an example for the addition, you figure out the rest:

$a = mt_rand();
$b = mt_rand();
echo "$a + $b = " . ($a + $b);

Upvotes: 2

Related Questions