lundi 26 février 2018

Random multiplication table generator

im creating an multiplication table system in PHP.

But I am trying to build my algorithm in such an way that if the user selects the table 7 and 20 questions that it would random give me 20 questions from the table 2 to the input number table, so 7.

At this point I just fill an array like this:

$nCount = $_POST['count'];
$nHighest = $_POST['table'];
$aSums = [];
$nCounter = 0;
while($nCount > 0){
    $cSumString = rand(2, $nHighest) . "*" . rand(1, 10);
    $aSums[$nCounter] =
    $nCount--;
    $nCounter++;
}

And this works even if there are better ways. so when I want to parse them all ill explode them on the *. but I want to parse them in multiple ways:

3 * 5 = ... (normal)
... * 5 = 25 (first number to fill in)
8 * ... = 16 (second to fill in)

This needs to be random aswell, so it can occur that there are 3 normal questions first then 2 second place to fill and then a normal again.

And to be honest im kind of clueless. I did alreade make some code to prevent the same questions like: 2*8 and 8*2 and so on. But for this im clueless.

Can anyone push me in the right direction? Im not asking for instacode or something im really willing to do this myself but everything ive tried up until now is completely rubbish. everytime I think ive got it I realise it doesnt work.

Thanks in advance and happy coding.




Aucun commentaire:

Enregistrer un commentaire