Coincidentally I was talking about this with someone earlier today. I used to have wet dreams quite frequently, maybe twice a month on average, and it was more common for me to have a wet dream if I’d had sex that evening, so I don’t think that it is 100% necessary to avoid sex or masturbation before bed, but I guess it’s logical that if you don’t, you’ll eventually be horny enough to have one?! :D