I want to generate a random number between 0 and 15, but never had the same number come up twice in a row.

I considered it like this:

<b>random rand</b> ' generate the random number
<b>num = rand & $000F</b> ' grab that last 4 bits of the number
<b>if num = last then start</b> ' compare the number to the previously stored number and if it is the same do it again
<b>last = num</b> ' store the number to compare next time

This seems like it should work, but it's not working for me. I am still getting duplicate consecutive random numbers. Is it because I am using a word to store four bits and if that is the case, what is the proper syntax to compare just 0 to 15 on those words?