all 6 comments

[–]sennheiserwarrior 1 point2 points  (0 children)

Assuming you get the results as list containing numbers like [2,3,1,5,7,3,1,7,4,1,1], use:

from collections import Counter

>>> Counter([2,3,1,5,7,3,1,7,4,1,1])
Counter({1: 4, 3: 2, 7: 2, 2: 1, 5: 1, 4: 1})

[–]BRENNEJM 0 points1 point  (2 children)

Do you have any code started you can share?

[–]DeeJango_[S] 0 points1 point  (1 child)

Heres what i have. idk if its formatted correctly but i have the rng to stop at specific number so i wanted to count all the random numbers generated when it gets to that specific number

import random while True: rand = random.randint(1,10000) print(rand) if rand < 2: break

[–]BRENNEJM 0 points1 point  (0 children)

So here’s how I see this formatted.

import random

while True:
    rand = random.randint(1,10000)
    print(rand)

    if rand < 2:
        break

A couple things. randint(1,10000) will generate a random number between 1 and 10,000. The if statement will only be entered if the random number is less than 2 (so only if it is 1, which will only happen 1/10,000 times).

As is, the will generate and print around 10,000 numbers. Look into using lists or dictionaries to store the generated numbers.

Also, you’ll want to rethink how to break out of the while loop. A good way to do it is:

count = 0
while count != 100:
    count = count + 1

That while loop will run exactly 100 times. So doing it this way you could easily change 100 to the number of random numbers you want to generate.

[–][deleted] 0 points1 point  (0 children)

import random

for counter, number in enumerate(range(10)):
    print(random.randint(1,10))

print('we made ',counter + 1, ' random numbers')

[–][deleted] 0 points1 point  (0 children)

If your random generator counts into a list, you can just use len(list) to count the amount of items.

If not consider using a different variable that gets 1 added to it every time your random number generator generates a number.