Pregunta de entrevista de J.P. Morgan

given a function that generates a random integer between 1:5 , how can we generate a random integer 1:7

Respuestas de entrevistas

Anónimo

6 feb 2019

run rand(1:5) twice and record the ordered pair . That makes 25 outcomes. Impose an ordering on these 25 pairs. Now, if the outcome belongs in the first 4 pairs, discard them and the procedure starts over. If not, then note that the remaining 21 pairs can be divided into 7 equally probable subsets.

1

Anónimo

30 ago 2018

rand(1:5)*rand(1:1.4) -- gives a float type

Anónimo

28 ago 2018

Generate X from 1:5, then (X-1)*6/4+1

1