3
I have a cycle For
that has two mt_rand
, one of random numbers and the other mt_rand
of numbers that are designated as prizes.
What I want now is to check when 3 equal numbers come out, make the sum of the values that came out in this mt_rand
of the 3 numbers and return in a variable with the total sum of these values.
PHP
for ($i = 0; $i<9; $i++){
$numeros = mt_rand(1,9);
$premio = mt_rand(1,20);
echo "valor" . ($i + 1) . "=$numeros&premio" . ($i + 1) . "=$premio&";
}
It is not clear enough this question to help you. Can you give us an example of how you want it to happen ?
– Diego Souza
This is a project like scratch card in the flash I have 9 squares and I have a boot buy the scratch card when I click buy it goes to php and in the cycle for generates the numbers of luck and the respective prizes that will appear in the boxes I want that when you leave 3 equal numbers it add the values of the prizes that leave in those 3 equal numeoros and return in a total variable the value to show in the flash
– César Sousa
usually in other languages, we create a list, and each random number we play in the list, so it’s easy to check if the number already exists in the list in C# would look something like this: if(! listRnd[]. Contains(new))
– Dorathoto
Make a version of your algorithm in natural language, step by step, which I put my suggestion of the PHP version. It will be a pleasure to help!
– Paulo Sérgio Duff
A natural language version as well ?
– César Sousa
As @Dorathoto said, in languages like C# and Java there are libraries that make it easy to solve this problem. You play all numbers in a list, and use, using Java as an example: Collections.Frequency(list, number) returns the frequency, List.contains(object) returns Boolean etc.. .
– Memphys
Yes but in php you can also do I think
– César Sousa
The three numbers must be equal in that example set, 5,5,5 (valid), 5,5,5,8 (possible invalid). That is to each group of three, all must be equal.
– rray