I have can generate random data like Alan Boyce suggested, and that
works to a point but as my models evolved I am looking for a more
general way of generate random data so that I don't have to mess with
the random generation section every time I change a model.

I am asking because I am still learning how to think in python, I am
used to statically defining almost everything in my program and I am
trying to learn how to think in abstractions and patterns.

On 12/6/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> You can use python.   Try:
>
> # Make a random phone number
> def mkphone():
>     import random
>     phone = ""
>     for i in range(10):
>         if (i == 3):
>             phone += "-"
>         if (i == 6):
>             phone += "-"
>         phone += str(random.randrange(0,9))
>     return phone
>
> # Based on
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/59865
>
> # make a random username
> def randomLine(filename):
>     "Retrieve a  random line from a file, reading through the file
> once"
>     fh = open(filename, "r")
>     lineNum = 0
>     it = ''
>     while 1:
>         aLine = fh.readline()
>         lineNum = lineNum + 1
>         if aLine != "":
>             #
>             # How likely is it that this is the last line of the file ?
>
>             if random.uniform(0,lineNum)<1:
>                 it = aLine
>         else:
>             break
>     fh.close()
>     return it
>
> I usually use a file like /usr/share/dict/names or something similar to
> make user names
>
> Best,
>
> Alan Boyce
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to