Reputation: 1
Can you use 'rand' to generate random operators? I have made a php program to add up two random numbers but I want to alter it and make the operator random. Is using 'rand' the best way. Thank you
Upvotes: 0
Views: 411
Reputation: 13535
well you can put operators in an array and then call array_rand to retrive it
$ops = array('+','-','*','/');
$rand_key = array_rand($ops);
$operator =- $ops[$rand_key];
Upvotes: 1