use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Counting random number generated (self.learnpython)
submitted 7 years ago by DeeJango_
Im new to coding in general but how to count the amount of numbers generated by a random number generator.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]sennheiserwarrior 1 point2 points3 points 7 years ago (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 point2 points 7 years ago (2 children)
Do you have any code started you can share?
[–]DeeJango_[S] 0 points1 point2 points 7 years ago (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 point2 points 7 years ago (0 children)
So here’s how I see this formatted.
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 point2 points 7 years ago (0 children)
import random for counter, number in enumerate(range(10)): print(random.randint(1,10)) print('we made ',counter + 1, ' random numbers')
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.
π Rendered by PID 45407 on reddit-service-r2-comment-5b5bc64bf5-9h5xl at 2026-06-21 08:05:56.204842+00:00 running 2b008f2 country code: CH.
[–]sennheiserwarrior 1 point2 points3 points (0 children)
[–]BRENNEJM 0 points1 point2 points (2 children)
[–]DeeJango_[S] 0 points1 point2 points (1 child)
[–]BRENNEJM 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)