Pergunta de entrevista da empresa Jether Energy

Given vector of probabilities that sum to one, write a code that samples according to that distribution. You are given access to a random generator that outputs a number between zero and one uniformly.