To generate a positive integer with exactly ten digits, call random.randint(1_000_000_000, 9_999_999_999). If you need a ten-character value that may begin with zero, generate a value from zero and format it as a zero-padded string instead.
Generate a ten-digit integer
Python’s randint(a, b) includes both endpoints. The smallest positive ten-digit integer is 1,000,000,000, and the largest is 9,999,999,999, so this range excludes nine-digit results and avoids an eleven-digit upper bound. See the Python random module documentation.
import random
number = random.randint(1_000_000_000, 9_999_999_999)
print(number)
Alternatively, random.randrange(1_000_000_000, 10_000_000_000) works because randrange excludes its stop value. Do not use randint(10**9, 10**10): its inclusive upper endpoint, 10,000,000,000, has eleven digits.
Include leading zeros when the output needs ten characters
An integer does not retain leading zeros. If the requirement is a fixed-width code or identifier, produce a string with a width of ten:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute#1 Best Overall
import random
number = random.randint(0, 9_999_999_999)
digits = f"{number:010d}"
print(digits)
If the generated value is 42, digits is 0000000042. Use the string for display or storage when those zeros matter; converting it back to an integer removes them.
Use a cryptographic generator for security-sensitive values
Python’s random module uses a deterministic pseudorandom generator and its documentation warns that it should not be used for security purposes. For passwords, authentication, security tokens, or other values that must be difficult to predict, use secrets, which is intended for cryptographically strong random values. See the Python secrets module documentation.
Rank #2
Positive ten-digit integer
import secrets
secure_number = secrets.randbelow(9_000_000_000) + 1_000_000_000
randbelow(n) returns a value from zero up to, but not including, n; adding 1,000,000,000 therefore gives a positive ten-digit integer.
Ten characters with possible leading zeros
import secrets
secure_digits = f"{secrets.randbelow(10_000_000_000):010d}"
This creates a ten-character string, including any leading zeros, using the security-oriented generator.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Generate several values and handle duplicates
Repeated calls are appropriate when duplicate values are acceptable. For example, this creates five ordinary pseudorandom integers; the same value can appear more than once:
import random
numbers = [random.randint(1_000_000_000, 9_999_999_999) for _ in range(5)]
If every result must be unique, repeated independent draws are not enough. Track values already selected and draw again when a duplicate appears, or use sampling without replacement when selecting from a defined sequence. The random documentation describes sampling without replacement for sequences. For security-sensitive unique values, apply an appropriate uniqueness check while generating with secrets.
Quick Recap
Best Value
Choose the form that matches your requirement
- Positive numeric value, exactly ten digits: use inclusive bounds from 1,000,000,000 through 9,999,999,999.
- Exactly ten displayed characters, leading zeros allowed: generate from zero through 9,999,999,999 and apply
:010dformatting. - Ordinary program behavior or simulation: use
random. - Hard-to-predict security value: use
secrets. - No repeated values: implement uniqueness handling; random generation alone does not guarantee it.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




