I have a list of choices in python like:
choices = ['A', 'B', 'C', 'D']
and a list of probabilities like:
probs = [0.5, 0.2, 0.1, 0.1]
they're related position-wise, A has a probability of 0.5, while D has a probability of 0.1.
I also have a list with ids:
list_ids = range(1000)
I want to obtain, for each element of the list, an element of the list of choices, something that could be done like:
import numpy as np
variants = np.random.choice(choices, len(list_ids), p=probs, replace=True)
However, I would like to have a deterministic mapping from the ids in the list to the choices, to be able to recover them from any computer at any moment. For that, I would use some kind of hashing function, something like:
hashes = [xxhash.xxh64(str(id)).intdigest() for id in list_ids]
and then do some operations on the hashes to guarantee that 50% of the samples go to A. How can I do that in python?
Thanks!
NOTE: Setting numpy the seed doesn't solve it for me, I'd like someone who doesn't even use python be able to know, for a given id, in which choice it was allocated according to the deterministic procedure.