Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32688
| From | Andriy Kornatskyy <andriy.kornatskyy@live.com> |
|---|---|
| Subject | RE: How to generate account number? |
| Date | 2012-11-03 11:42 +0300 |
| References | <50944ba2$0$29967$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3235.1351932226.27098.python-list@python.org> (permalink) |
Steven, see below, please. ---------------------------------------- > From: steve+comp.lang.python@pearwood.info > Subject: Re: How to generate account number? > Date: Fri, 2 Nov 2012 22:39:31 +0000 > To: python-list@python.org > > On Sat, 03 Nov 2012 00:13:19 +0300, Andriy Kornatskyy wrote: > >> Requirements for `account number` generator: >> >> 1. Issue pseudo random consistent number (must be unique for dozen >> millions of records) > > How much randomness do you need? From the perspective of any one user, a > simple incrementing counter returns arbitrary values, which may be "close > enough" to random. > > last_num = 103872 # Pick an arbitrary starting value. > def get_account_number(): > """Return the next account number.""" > global last_num > last_num += 1 > return last_num > > Stick that value in a database instead of a global, and you're done. > > What are the consequences of people guessing account numbers? If the > consequences are serious, then you need to make account numbers > cryptographically strong. If the account number alone is not important, > then you don't. Yes. There are consequences to not use sequential numbers, yet humans deal with it (enter as input somewhere, etc). The approach suggested here: http://mindref.blogspot.com/2012/11/generate-account-number.html is using Feistel cipher to generate pseudo random thus makes guessing account numbers hard (impossible?). >> 2. Easy check validity (without a need to make a database call) > > Add a check digit to the number you generate. There are all sorts of ways > to do that. Here are two examples: > > http://code.activestate.com/recipes/577692 > http://code.activestate.com/recipes/577691 These tell me how to verify some code, but doesn't how to generate it. The approach suggested here: http://mindref.blogspot.com/2012/11/generate-account-number.html gives you ability to customize `sample_f` function to make it unique to your business case. >> Interested? Read more here: > > If you ask a question here, please keep the discussion here, don't split > it to your personal blog. The question was rhetorical with my answer in the blog and discussion here to reach something. > Tell us your requirements in more detail, and we will try to help you. I have presented solution to `account number` challenge. So it was share with community and seek for thoughts if any.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How to generate account number? Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-03 00:13 +0300
Re: How to generate account number? GangGreene <GangGreene@example.com> - 2012-11-02 18:02 -0400
RE: How to generate account number? Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-03 11:38 +0300
Re: How to generate account number? Roy Smith <roy@panix.com> - 2012-11-03 09:22 -0400
Re: How to generate account number? Tim Chase <python.list@tim.thechases.com> - 2012-11-03 10:34 -0500
RE: How to generate account number? Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-03 19:18 +0300
RE: How to generate account number? Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-03 19:23 +0300
Re: How to generate account number? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-02 22:39 +0000
RE: How to generate account number? Andriy Kornatskyy <andriy.kornatskyy@live.com> - 2012-11-03 11:42 +0300
csiph-web