Posted on April 16, 2007 at 12:27 A.M.

I use this function all the time, most recently for some anti-spam techniques, and it's worth posting somewhere. It's modified from an entry on the activestate cookbook.

def random_chars(length):
    import random
    allowed_chars = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWZYZ0123456789"
    word = ""
    for i in xrange(0, length):
        word = word + allowed_chars[random.randint(0,0xffffff) % len(allowed_chars)]
    return word

Also, for anyone who knows me and is interested: my surgery went well and I'm recovering faster than I would have expected. Hopefully I'll be back to 100% speed in the next few days!

Anyways, hopefully this small code snippet is useful to someone else, as well!

stroky.l@gmail.com
at 5:01 a.m.
on Aug. 2, 2007

Python

why not that ??

def random_chars(length):

from random import randrange

allowed_chars = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWZYZ0123456789"

word = ""

for i in xrange(0, length):

word = word + allowed_chars[randrange(0,len(allowed_chars)]

return word

Search

 

Recent Links

  • git-issues: A distributed issue tracker built-in to Git.
  • I predicted this back in March--can't believe a solution has surfaced so soon. It makes so much sense to build in an issue tracker to a revision control system. Since you're working with the code, might as well track the issues in the same system and take advantage of the extra metadata. This is really cool (and as a bonus, it's written in Python) so I hope to see it really grow and flourish!

  • How I Work Daily
  • Daily blog by Kevin Fricovsky. In addition to having some really great content, he has started to post audio interviews with people from the Django community. This is a site to keep an eye on in the coming days and months.

  • django-arcade
  • Demo site for django-arcade, an open source reusable Django app to add new flash games to any django-powered site. Looks very cool for easily creating game portals. It also comes from my future employer.

  • Facebook Chat and Scalability (with Erlang)
  • Eugene Letuchy talks about how they they took Facebook Chat from no users to 70 million users, with the help of Erlang.

  • Simon Willison: The Implications of OpenID
  • I somehow missed this presentation when it came out, but it's an absolutely fantastic overview and defense of OpenID by Simon Willison. If you are in any way interested in what OpenID is and what it can offer, you owe it to yourself to check out this presentation.

  • StupidXML
  • Probably the simplest XML library that I've seen for Python. Sometimes you just want to generate some stupid XML, and this is the perfect tool for the job.

  • See the rest of my links...

Pownce

Badges

  • django badge
  • apache badge
  • GeoURL
  • XFN Friendly
  • Valid HTML 4.01 Transitional