Random Function Bias Tester I wanted to create a short little piece of code so that I could see the biases in the random function.

import random
import statistics
import time

num = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
average = []

while True:
    randomNum = random.randint(0, 9)
    num[randomNum] += 1
    average.append(randomNum)
    print(f"\nThe average for all the numbers is {round(statistics.mean(average), round(sum(num) / 20))}")  # The second part of the round function is to keep as few digits on screen while still showing changes with every number. 20 is the arbitrary number I found worked best.
    print(f"The most common number is {num.index(max(num))}\n")
    time.sleep(0.5)



Since I am new-ish to python I wanted to know if, even though its only 15 lines, that I am following good coding practices. That way when my code gets more complicated, I don't have to worry about that as much
Hard coding your data can be lengthy and it can restrict flexibility when carrying out further analysis. You can shorten your code with list comprehension. 

import random

n = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

def main(val):
  ls = [i for i in random.choices(n, k=val)]
  ns = sum(ls)/len(ls)
  print('Length of Data : {}\nSum of Data    : {}\nAverage of Data: {}\nRandom Gen Data: {}'.format(len(ls), sum(ls), ns, ls))

main(100) #Enter amount of data you want to pass through the function


This returns:

Length of Data : 100
Sum of Data    : 399
Average of Data: 3.99
Random Gen Data: [7, 4, 0, 8, 8, 0, 6, 7, 6, 4, 7, 0, 0, 0, 9, 4, 3, 0, 0, 7, 0, 4, 6, 5, 3, 0, 6, 0, 7, 0, 0, 4, 3, 7, 7, 9, 5, 3, 5, 2, 0, 4, 1, 1, 5, 8, 9, 0, 3, 2, 7, 5, 3, 3, 3, 3, 7, 5, 7, 5, 7, 1, 6, 2, 7, 7, 5, 1,6, 6, 4, 7, 8, 2, 0, 1, 5, 3, 5, 4, 9, 7, 7, 2, 0, 3, 4, 6, 3, 4, 3, 5, 6, 3, 0, 1, 3, 8, 0, 1]


It isn't necessary to use a while loop in this instance because you will still need to break your loop which is the same as giving a start and end value to a random range reference.