Justin Barry
Justin Barry

Reputation: 1

Can you use 'rand' to generate random operators?

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

Answers (2)

rcyboom
rcyboom

Reputation: 21

may be you can use random and round and switch structor

Upvotes: 0

DevZer0
DevZer0

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

Related Questions