I wonder what % and & in the following PHP code do.
$num_one = rand() % 10;
$num_two = rand() & 10;
Thanks in advance.
I wonder what % and & in the following PHP code do.
$num_one = rand() % 10;
$num_two = rand() & 10;
Thanks in advance.
&
is the bitwise AND operator. %
is the modulus (remainder of rand() / 10
in this case).
% is modulo, so
$num_one = rand() % 10
gives you a number between in [0..10), while & means bitwise and, such that
$num_one = rand() & 10
gives you a random number with only a combination of the bits 2 and 4 set, like in [2,8,10].