[Tutor] Randomize SSN value in field

W W srilyk at gmail.com
Thu May 22 19:20:07 CEST 2008


Oops! Maybe it works better with reply to all:

You're looking for a completely random 9 digit number that you can't
derive the name from?

I don't know that anything would really be more or less secure than
simply using random.
>>> import random
>>> random.randrange(100000000,999999999)
988559585
>>> random.randrange(100000000,999999999)
905877832
>>> random.randrange(100000000,999999999)

Just for kicks and giggles, I've tried and at least 35,000 records
came up with no repeats. Of course you'd want to check that, and the
easiest way is using a dict/hashtable.

I'm checking to see if out of 500,000 records I can generate a
repeated value, though.

Is there any particular reason you're worried about using random to
generate the fake SSN? At least, one that you can share with us?

-------

I went ahead and wrote a program to generate 500,000 random SSNs, and
I got a total of 132 repeats (assuming my code works how I wanted it
to). If I'm correct in my math, that's about a .0003% chance of
repeat, using the same system.

Also just FYI, it took about 23 seconds to generate all 500,000.

if you would like to see my code, just ask!

HTH,
Wayne

On Thu, May 22, 2008 at 11:14 AM, GTXY20 <gtxy20 at gmail.com> wrote:
> Hello all,
>
> I will be dealing with an address list where I might have the following:
>
> Name SSN
> John 111111111
> John 111111111
> Jane 222222222
> Jill 333333333
>
> What I need to do is parse the address list and then create a unique random
> unidentifiable value for the SSN field like so:
>
> Name SSNrandomvalue
> John 1a1b1c1d1
> John 1a1b1c1d1
> Jane 2a2b2c2d2
> Jill 3a3b3c3d3
>
> The unique random value does not have to follow this convention but it needs
> to be unique so that I can relate it back to the original SSN when needed.
> As opposed to using the random module I was thinking that it would be better
> to use either sha or md5. Just curious as to thoughts on the correct
> approach.
>
> Thank you in advance.
>
> G.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn't. - Primo Levi


More information about the Tutor mailing list