How about adding another ifelse:
ifelse(a>b, 1, ifelse(a==b, sample(1:2, length(a), replace = TRUE), 0))
In this case you get the value 1 if a>b, then, if a is equal to b it is either 1 or 2 (sample(1:2, length(a), replace = TRUE)
), and if not (so a must be smaller than b) you get the value 0.