There are many ways to do this. The easiest is to remember which item was returned the last time, and check the next item picked against that, and if it’s the same, simply pick again, in a loop.
As long as there is more than one item to pick from, this loop will always finish quickly because of properties of pseudo-random generators – there is actually no risk of an infinite loop.