from typing import Tuple, Any, List
from itertools import starmap, chain, repeat
from random import choice
from collections import Counter
def sample_space(*values: Tuple[Any, float]) -> List:
if sum(value[1] for value in values) != 1.0:
raise ValueError('Soma das probabilidades não é 1.0')
while True:
if all(probability.is_integer() for _, probability in values):
break
values = [(value, probability * 10) for value, probability in values]
values = [(value, int(probability)) for value, probability in values]
return list(chain(*starmap(lambda a, b: list(repeat(a, b)), values)))
space = sample_space((1, 0.4), (7, 0.3), (15, 0.3))
samples = [choice(space) for _ in range(100)]
print(Counter(samples))
ZnJvbSB0eXBpbmcgaW1wb3J0IFR1cGxlLCBBbnksIExpc3QKZnJvbSBpdGVydG9vbHMgaW1wb3J0IHN0YXJtYXAsIGNoYWluLCByZXBlYXQKZnJvbSByYW5kb20gaW1wb3J0IGNob2ljZQpmcm9tIGNvbGxlY3Rpb25zIGltcG9ydCBDb3VudGVyCgpkZWYgc2FtcGxlX3NwYWNlKCp2YWx1ZXM6IFR1cGxlW0FueSwgZmxvYXRdKSAtPiBMaXN0OgogICAgaWYgc3VtKHZhbHVlWzFdIGZvciB2YWx1ZSBpbiB2YWx1ZXMpICE9IDEuMDoKICAgICAgICByYWlzZSBWYWx1ZUVycm9yKCdTb21hIGRhcyBwcm9iYWJpbGlkYWRlcyBuw6NvIMOpIDEuMCcpCiAgICB3aGlsZSBUcnVlOgogICAgICAgIGlmIGFsbChwcm9iYWJpbGl0eS5pc19pbnRlZ2VyKCkgZm9yIF8sIHByb2JhYmlsaXR5IGluIHZhbHVlcyk6CiAgICAgICAgICAgIGJyZWFrCiAgICAgICAgdmFsdWVzID0gWyh2YWx1ZSwgcHJvYmFiaWxpdHkgKiAxMCkgZm9yIHZhbHVlLCBwcm9iYWJpbGl0eSBpbiB2YWx1ZXNdCiAgICB2YWx1ZXMgPSBbKHZhbHVlLCBpbnQocHJvYmFiaWxpdHkpKSBmb3IgdmFsdWUsIHByb2JhYmlsaXR5IGluIHZhbHVlc10KICAgIHJldHVybiBsaXN0KGNoYWluKCpzd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