PHP random number generation with condition
numbers, php, random
Solution
function getMoreRandom()
{
do {
$temp = 5 * (getRandom() - 1) + getRandom();
} while ($temp > 21);
return $temp % 7 + 1;
}
Problem
I was recently given a task to accomplish which i failed. I don't usually ask for logic but today i am compalled to ask.Here is the task. I am not allowed to use rand() function of php. instead i can use this function. ``` function getRandom() { return rand(1,5); } ``` OK i tried this function but it is bound to return value from 3 to 7. ``` function getMoreRandom() { $value = getRandom(); return $value + 2; } ``` Now i have to define a php function which can return me random number with the range 1 to 7. How can i do this?