Skip to main content
edited tags
Link
smci
  • 34.2k
  • 21
  • 118
  • 153
edited tags
Link
Salman Arshad
  • 273.7k
  • 85
  • 451
  • 541
Question Protected by Sneftel
added 3 characters in body; edited title
Source Link

How to generate a random 4 digit number not starting with 0 and having unique digits in python?

This works almost fine but the number starts with 0 sometimes:

import random
numbers = random.sample(range(10), 4)
print(''.join(map(str, numbers)))

This works almost fine but the number starts with 0 sometimes. II've found a lot of examples but none of them guarantee not startingthat the sequence won't start with 00. Thanks for your help!

How to generate a random 4 digit number not starting with 0 and having unique digits in python?

import random
numbers = random.sample(range(10), 4)
print(''.join(map(str, numbers)))

This works almost fine but the number starts with 0 sometimes. I found a lot of examples but none of them guarantee not starting with 0. Thanks for your help!

How to generate a random 4 digit number not starting with 0 and having unique digits?

This works almost fine but the number starts with 0 sometimes:

import random
numbers = random.sample(range(10), 4)
print(''.join(map(str, numbers)))

I've found a lot of examples but none of them guarantee that the sequence won't start with 0.

Source Link
Menon A.
  • 580
  • 1
  • 5
  • 13
Loading