Ran into potentially undefined behaviour (?) when initialised with a probability distribution that does not sum to 1.
Unless there is a misunderstanding (which should be clarified in the description), I propose to add a simple check such as sum(dist) == 1).