For some my cat will randomly bite me. He's very sweet to me 99% of the time, but a couple weeks ago I was casually walking by him when he bit my foot till blood. Yesterday I was falling asleep in bed when he decided to bite my elbow hard.
I've tried everything to get him to stop (this has been an ongoing problem for over three years now). Scruffing him, ignoring him for a few hours to show him I'm hurt, etc (except for the water bottle which I really don't want to use) did absolutely nothing to deter him.
I'm not happy to say it, but the only thing that has worked is if I spank him. Afterwards he doesn't try to bite me for at least a few months. Then it happens again. I know some people are vigorously typing right now that I should NEVER hit my cat, but that's why I'm even posting this question. Spanking is the only thing that has worked so far and he isn't afraid of me afterwards or flinching when I pet him, but I really would like to avoid it. Does anyone know a better way to get a cat to stop biting you?

Some details:
-The only person in my family he bites is me ( I am a teenager and only child).
-It literally comes from nowhere. Most of the time it's when I'm doing my own thing like reading.
-usually if he wants attention he meows loudly or pats my foot with his paw so I don't think that's the problem
-we adopted him as an adult
-I've had cats before. They haven't tried to bite me out of the blue like him
-If I can't get him to stop my family will give him away