vendredi 27 janvier 2017

Generate f(8) function using f(4) function where f(4) generates 1 to 4 randomly? [on hold]

I am facing problem to generate a function named f(8) which will generate 1 to 8 randomly using a defined function f(4) which generates 1 to 4 randomly. need help in this.

EDIT

This question was asked in HackerRank problems. As I don't have any mathematical background I felt hard to solve this. My implementation was like this,

def f8():
    return f4() + f4()

But this implementation is incorrect as it will never be able to produce 1 and the probability of each element is not 1/8 (as by random we mean each and every element in the range has same chance of occurrence)

Some guys thought that this question is not related to programming and I can totally understand the mistake I did and tried to correct that mistake. Hope I am able to convey what I actually did mean.




Aucun commentaire:

Enregistrer un commentaire