Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavinblair/1010675 to your computer and use it in GitHub Desktop.
Save gavinblair/1010675 to your computer and use it in GitHub Desktop.
Generate a random math question that always has a positive answer
<?php
$ops = array('-', '+');
$answer = -1;
while($answer < 0 || $answer > 99) {
$num1 = rand(0, 100);
$num2 = rand(0, 100);
$num1 -= 50;
$num2 -= 50;
shuffle($ops);
$op = $ops[0];
$answer = eval("return $num1 $op $num2;");
}
return "$num1 $op $num2 = $answer";
@Darius-doku
Copy link

cool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment