How could I make this code more "automated"?
Question: I did this code yesterday trying to test how really random are the random
numbers that Python generates:

    
    
    # -*- coding: cp1252 -*-
    import random
    print "Bienvenido al Analizador del Azar, este programa generará 100 números para aleatorios, para luego dar en tanto por ciento la cantidad de cada uno."
    numeros_aleatorios = []
    contador = 0
    while True:
        namber = random.randint(1,10)
        numeros_aleatorios.append(namber)
        contador += 1
        if contador == 100:
            break
    PR1 = float(numeros_aleatorios.count(1)) / 100
    PR2 = float(numeros_aleatorios.count(2))/ 100
    PR3 = float(numeros_aleatorios.count(3)) / 100
    PR4 = float(numeros_aleatorios.count(4)) / 100
    PR5 = float(numeros_aleatorios.count(5)) / 100
    PR6 = float(numeros_aleatorios.count(6)) / 100
    PR7 = float(numeros_aleatorios.count(7)) / 100
    PR8 = float(numeros_aleatorios.count(8)) / 100
    PR9 = float(numeros_aleatorios.count(9)) / 100
    PR10 = float(numeros_aleatorios.count(10)) / 100
    
    print "Hay exactamente un", PR1, "% de 1s"
    print "Hay exactamente un", PR2, "% de 2s"
    print "Hay exactamente un", PR3, "% de 3s"
    print "Hay exactamente un", PR4, "% de 4s"
    print "Hay exactamente un", PR5, "% de 5s"
    print "Hay exactamente un", PR6, "% de 6s"
    print "Hay exactamente un", PR7, "% de 7s"
    print "Hay exactamente un", PR8, "% de 8s"
    print "Hay exactamente un", PR9, "% de 9s"
    print "Hay exactamente un", PR10, "% de 10s"
    

As you can see, I had to put PR1, PR2, PR3... manually to make every %, and
then write every print to display the results. My question is, is there any
way to make this more automated, so I don't have to write every line
indivually? It would be very useful for my next projects.


Answer: A
[collections.Counter](https://docs.python.org/2/library/collections.html#collections.Counter)
will do all the counting for you, and use `range` to loop in the number of
trials you want to run:

    
    
    from collections import Counter
    
    trial = 100
    counts = Counter(random.randint(1,10) for _ in range(trials))
    print(counts)
    Counter({3: 17, 7: 12, 8: 12, 9: 12, 4: 11, 6: 9, 2: 8, 10: 8, 5: 6, 1: 5})
    
    
    
    for i in range(1,11):
        print("Hay exactamente un {}% de {}".format(100 * counts[i] / float(trials),i))
    

Output:

    
    
    Hay exactamente un 11.0% de 1
    Hay exactamente un 6.0% de 2
    Hay exactamente un 12.0% de 3
    Hay exactamente un 12.0% de 4
    Hay exactamente un 9.0% de 5
    Hay exactamente un 4.0% de 6
    Hay exactamente un 10.0% de 7
    Hay exactamente un 14.0% de 8
    Hay exactamente un 12.0% de 9
    Hay exactamente un 10.0% de 10
    

No idea if _Hay exactamente un_ is in the correct order!

