Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #22202 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2012-03-26 10:48 -0600 |
| Last post | 2012-03-26 10:48 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: random number Ian Kelly <ian.g.kelly@gmail.com> - 2012-03-26 10:48 -0600
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-03-26 10:48 -0600 |
| Subject | Re: random number |
| Message-ID | <mailman.1013.1332780512.3037.python-list@python.org> |
On Mon, Mar 26, 2012 at 3:24 AM, Michael Poeltl
<michael.poeltl@univie.ac.at> wrote:
>>>> import random, string
>>>> def random_number(id):
> ... characters = list(string.ascii_lowercase +
> ... string.ascii_uppercase +
> ... string.digits)
> ... coll_rand = []
> ... for i in range(6):
> ... random.shuffle(characters)
> ... coll_rand.append(characters[0])
> ... return ''.join(coll_rand)
You don't need to do all that list manipulation. This is probably quicker:
def random_number(): # Unused "id" parameter omitted
characters = (string.ascii_lowercase +
string.ascii_uppercase +
string.digits)
return ''.join(random.choice(characters) for i in range(6))
Cheers,
Ian
Back to top | Article view | comp.lang.python
csiph-web