Pergunta de entrevista da empresa eBay

Some probability question 1) given a rand5() function which provide a random number between 1-5 at equal probability. Write a rand7() fuction to provide a random number between 1-7 with equal probability...

Respostas da entrevista

Sigiloso

1 de abr. de 2016

The answer Abs(2*rand5()-3 ) does not generate uniformly distributed random numbers. It is wrong!

3

Sigiloso

7 de fev. de 2014

int value = rand5() - 1 + (rand5() * 5); if(value < 21) { return (value%7 +1); }

1

Sigiloso

7 de mar. de 2014

int value=0 for (i=0; i<5; i++) { value+=(rand5()-1);} return (value%3+1);

Sigiloso

3 de jun. de 2013

int value = rand5()-1 + (rand5()-1)*5; if (value < 21) { return( value / 3 +1); }

1

Sigiloso

4 de abr. de 2013

Abs(2*rand5()-3 )

5