Six-Digit OTP Generator

Easy ⏱ 8 min 79% acceptance ★★★★★ 4.9
Write make_otp(rng=None) returning a 6-character string of digits. Use the random module's choices over the digit characters; accept an optional pre-seeded random.Random instance for testability, defaulting to the module-level functions.

Examples

Example 1
Input
make_otp(random.Random(1))
Output
a deterministic 6-digit string like '134878'
Explanation

Seeding makes the output reproducible for tests.

Constraints

  • Exactly 6 characters, all digits.
  • Leading zeros are allowed — hence a string.

Topics

Modules & Packagesrandom

Companies

PayPalRazorpayHDFC Bank

Hints

Hint 1

''.join(choices('0123456789', k=6)).

Hint 2

rng = rng or random — both expose .choices.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.