hash(str) is non-deterministic, probably because it is using the internal
object ID or something and not the string content?
In any case, explicitly hash the string content and use that instead.
Also, sort the input pre-shuffle to ensure that variations in the original
host list ordering don't screw with the result.
Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit
adceaa9b28278601c56a7db1c3f42eaa592ec4d1)
+import hashlib
import logging
import random
from typing import List, Optional, Callable, TypeVar, Tuple, NamedTuple, Dict
# shuffle for pseudo random selection
# gen seed off of self.spec to make shuffling deterministic
- seed = hash(self.spec.service_name())
- random.Random(seed).shuffle(ls)
-
+ seed = int(
+ hashlib.sha1(self.spec.service_name().encode('utf-8')).hexdigest(),
+ 16
+ ) % (2 ** 32)
+ final = sorted(ls)
+ random.Random(seed).shuffle(final)
return ls