Julius Randle scored 28 points as the Brooklyn Nets beat the Milwaukee Bucks 104-97, snapping a five-game losing streak.