num_tokens = text.count(token)
points = [0] + sorted(random.sample(list(range(1, num_tokens + 1)), num_replacements)
    ) + [num_tokens + 1]
replace.join(token.join(text.split(token)[i:j]) for i, j in zip(points,
    points[1:]))
Python: How to replace N random string occurrences in text?