-3

Two questions:

  1. How to create a char+number random string. one char and 2 digit numbers for example: U12 OR W82

  2. How to create a random 5 digit number with no zero at the beginning: 02345 , 03243

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Alex Seifi
  • 80
  • 1
  • 7
  • 1
    Please keep your posts to **one** question per post. Your question is not specific to Flask, so I removed that tag. – Martijn Pieters Mar 28 '15 at 14:40
  • 1
    You state you want a random 5 digit number but *no zero* at the beginning, then show two examples of random numbers with a zero at the beginning. – Martijn Pieters Mar 28 '15 at 14:42
  • 1
    And my standard response to any give-me-the-code question: It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, stack traces, compiler errors - whatever is applicable). The more detail you provide, the more answers you are likely to receive. – Martijn Pieters Mar 28 '15 at 14:44
  • Your second question is a duplicate of [How to generate random number with the specific length in python](http://stackoverflow.com/q/2673385), there are probably duplicates for the first part too. – Martijn Pieters Mar 28 '15 at 14:45
  • @MartijnPieters Anyhow there are some good people out there that could understand my question and answered it correctly without any confusion. – Alex Seifi Mar 28 '15 at 14:46
  • 1
    We want questions to be useful to not just you, but to others as well. Moreover, by asking two questions you make it *harder* for people to answer. What if they only know the answer to one of the questions, and someone else knows the answer to the other? What answer will you then pick as the 'best' one? – Martijn Pieters Mar 28 '15 at 14:47

1 Answers1

2

1)

import random, string
"%c%02d" % (random.choice(string.uppercase), random.randint(0, 99))

2)

import random
random.randint(10000, 99999)
Samuel Tardieu
  • 2,071
  • 1
  • 14
  • 17