You cannot generate a random number that will have gap in the distribution.
So, the best way is to pick a random number and check it. If it picked 7, then you loop back and pick again.
Alternatively, you could have an array of dimension 8 that contains the number from 1 to 9, except 7.
Then you get a random number from 1 to 8, and that number is the index to the array. If it picked 7, then it would return the number in the 7th slot, which is 8.
(actually since c++ have array index starting at 0, it would be from 0 to 7, but you get the idea).
The down size is that you have to have that pre-populated array.