employer cover photo
employer logo

Pergunta de entrevista da empresa Nuance

Given a random number generator that provides a decimal number rand from [0, 1), write a function that returns a random integer from (1, 5].

Resposta da entrevista

Sigiloso

22 de out. de 2021

To flip the inclusion, subtract 1 - rand. Then multiply and truncate or simply divide the pieces such that there is a 25% chance of returning 2, 3, 4, and 5 respectively