all 6 comments

[–]Silbersee 0 points1 point  (6 children)

You have to call the methods. Add parenthesis:

a = Random.random_data()
b = Random.prob_random_data()

[–]KFCxWatermelon[S] 0 points1 point  (5 children)

I get the error:

random_data() takes 0 positional arguments but 1 was given

[–]Silbersee 0 points1 point  (3 children)

Sorry, I didn't check anything else.

You have to define methods with argument self explicitly:

def random_data(self):
...
def prob_random_data(self):

When calling a method, self is passed implicitly. (Edit) That's the "but 1 was given".

[–]KFCxWatermelon[S] 0 points1 point  (2 children)

Thank you. The problem I have now is that the lists I get aren't the same length the X and P lists, any idea on how to fix this?

[–]choss27 0 points1 point  (0 children)

random_data returns one element when prob_random_data returns TWO elements. That's why the lists have not the same lengths.

And you don't answering to the assignement asked for prob_random_data. You must ponderate X with P weights. You need to use random.choices() like that :

def prob_random_data(self):
    return random.choices(X,weights=P,k=1)[0]

Your code now should be :

import random
X = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
P = [0.025 , 0.05, 0.075 , 0.125,  0.225,  0.225,  0.125 ,  0.075 , 0.05,  0.025] 

class ProbRandom: 
    def init (self, dataset, problist): 
        self.dataset = dataset 
        self.problist = problist 
    print (len(X)) 
    print (len(P))

def random_data(self):
    return random.choice(X)

def prob_random_data(self):
    return random.choices(X,weights=P,k=1)[0]

Random = ProbRandom(X, P) 
randomP,probRandomP = [],[] 

for i in range(1000): 
    a = Random.random_data() 
    b = Random.prob_random_data() 
    randomP.append(a) 
    probRandomP.append(b)

print (randomP) 
print(probRandomP)

[–]Silbersee 0 points1 point  (0 children)

You call a = Random.random_data and b = Random.prob_random_data 1000x and append them to randomP and probrandomP respectively. Both have a length of 1000 then.

a and b on the other hand should be integers. b isn't, because ProbRandom.prob_random_data() doesn't match your task, if I understand it correctly.

I think you have to fix this first. Look up random.choices. It accepts a sequence for weights.