Question d’entretien chez J.P. Morgan

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

Réponses aux questions d'entretien

Utilisateur anonyme

6 févr. 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

Utilisateur anonyme

30 août 2018

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

Utilisateur anonyme

28 août 2018

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

1