Random module always prints same numbers

Tell us what’s happening:
Describe your issue in detail here.

Every time I run the code, same aleatory numbers are created.

Your code so far

import copy
import random
# Consider using the modules imported above.

class Hat:  
  def __init__(self,**arguments):
    self.contents=[]

    for k, j in arguments.items():
     while j > 0:
       self.contents.append(k)
       j-=1

  def draw(self, ball_number):
    self.removed=[]
    if ball_number>len(self.contents):
      return self.contents
    i=0
    while i < ball_number:
      aleatory=random.random()
      remove=int(aleatory*(len(self.contents)-1))
      self.removed.append(self.contents[remove])
      self.contents.pop(remove)
      i+=1  
    return self.removed
    

def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
  success=0
  for i in range(num_experiments):
    tested_hat=copy.copy(hat)
    tested_hat.draw(num_balls_drawn)
    all_found=1
    for k, j in expected_balls.items():
        while j>0:
          try:
            tested_hat.remove(k)
            j-=1
          except:
            j=-1
            all_found=0
    if all_found==1:
      success+=1
  probability=success/num_experiments
  return probability

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36

Challenge: Probability Calculator

Link to the challenge:

That’s because the main-module which runs the tests contains a seed for the random module. And that is intentional because writing a test for TRULY random numbers is kinda impossible. With a seed however, the “random” order is fixed and thus has one expected result which is easy to test.

Thank you! That makes sense as otherwise the test_hat_draw would be imposible to get. In fact, having other problems, I saw that repetition and instead of continuing using randint I made it just with random.random and faild that test. Really appreciated

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).