Please use the "Insert Code Snippet" button in the toolbar when including code examples with your comments.
A single equals sign "=" represents assigment, where as double or triple equals signs ("==" or "===") represent comparision. So your (if: $variable = 1) statement is actually telling Harlowe to assign the number 1 to the $variable story variable, and then to check if the over all result of that is true(ish).
The common confusion of using the wrong number of equals signs is one reason the to (assignment) and is (comparision) keyword operators exist. I suggest you use them instead of the equal signed.
A modified copy of your example
(set: $variable to (random: 1, 2))
(if: $variable is 1)[
(else-if: $variable is 2)[
note: you may notice in the above example that there is no white-space between the close parentheses ")" of the macro call and the open square bracket "[" of it's associated hook.