I am a begginer at python and only know the very basics. I was wondereing if anyone was experienced at Python and had any time to help a begginer. As far as first projects go I wanna make a program that can generate random numbers, letters, or words (in 3 different programs of course). If anyone could help, it would be great! :)

Dani AI

Generated

asked for beginner help generating random numbers, letters, and words. pointed to Python's randomness tools — a good start — and noted the forum sections. Today the practical approach is to use Python 3 and pick the right module for the job: the standard random module for simple tasks, and the secrets module when you need unpredictable values (passwords, tokens). Use string for letter sets and argparse to make a single, reusable script instead of three separate files.

A compact pattern that works on most systems: one script with a mode argument (numbers, letters, words). It reads an optional wordlist (for example /usr/share/dict/words on Unix-like systems) and uses secrets to choose items. This avoids reusing the small-sample examples already shown earlier and gives a safe default for most beginner projects.

#!/usr/bin/env python3
import argparse, secrets, string, sys

def nums(n, low, high):
    for _ in range(n):
        yield str(secrets.randbelow(high - low + 1) + low)

def letters(n, length, charset=string.ascii_lowercase):
    for _ in range(n):
        yield ''.join(secrets.choice(charset) for _ in range(length))

def words(n, path):
    try:
        with open(path, encoding='utf-8') as f:
            words = [w.strip() for w in f if w.strip()]
    except OSError:
        sys.exit('word list not found: ' + path)
    for _ in range(n):
        yield secrets.choice(words)

Troubleshooting tips: Windows may not have a system wordlist; install a small list or use NLTK/word-frequency packages. If you only need non-security randomness for games or tests, the random module is fine. Test small values first and confirm your Python version is 3.6+ for secrets. This pattern scales cleanly and keeps each feature easy to expand.

Recommended Answers

All 3 Replies

isn't there sa pythin section in this forum ?

[...]I wanna make a program that can generate random numbers, letters, or words (in 3 different programs of course). If anyone could help, it would be great! :)

Probably the first place to look is the random library. Specifically these functions:

>>> import random
>>> print random.random()
0.37449984017
>>> print random.randrange(2,87)
20
>>> print random.choice("ABC")
B
>>> print random.choice(["Ask","what","Python","can","do","for","you"])
what
>>>

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.