Python Random number frequency dictionary
Question: I am trying to make a function generates two random integers in rage 1 to 6.
And have a frequency dictionary of the sum of two integer values.

It is for simulating two dice rolling x number of times.

Here is my code and my code:

    
    
    def sim():
        dictionary = {}
        loop_value = 0
        total = 0
    
        while loop_value < 10:
            num_1 = random.randint(1, 6)
            num_2 = random.randint(1, 6)
    
            total = total + num_1 + num_2
    
            if value in dictionary:
                dictionary[total] += 1
            else:
                dictionary[total] = 1
    
            loop_value += 1
            print("Loop value", str(loop_value))
            print(dictionary)
    

This code just adds all the values up. So no every value is unique. How do I
fix this problem?


Answer: While Martins answer probably fixes your problem, you could use
[`collections.Counter`](https://docs.python.org/3.4/library/collections.html#counter-
objects) for a bit more flexible approach to counting.

Here's a quick example:

    
    
    >>> from collections import Counter
    >>> Counter(random.randint(1, 6) + random.randint(1, 6) for x in range(10))
    Counter({3: 3, 6: 3, 5: 2, 10: 1, 7: 1})
    

Counters are dictionaries, so you can manipulate them in the same way.

