Generate consistent person data

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Generate consistent person data



I want to use Faker to generate some data for tests.



But I have trouble generating consitent data for a single user:


>>> from faker import Factory

>>> fake = Factory.create()

>>> fake.name()
>>> u'Tayshaun Corkery'

>>> fake.email()
>>> u'kaitlynn40@yahoo.com'



As you see the email doesn't reflect the previously generated name. The docs say:



Each call to method fake.name() yields a different (random) result.
This is because faker forwards faker.Generator.method_name() calls
to faker.Generator.format(method_name).


fake.name()


faker.Generator.method_name()


faker.Generator.format(method_name)



Is there a way to generate consistent person data without writing much of additional code?




2 Answers
2



I am afraid not. Let me say if there was one, which apparently supposed to be simple_profile() or seed(), but actually doesn't work out that way.



I guess the only inconsistent data as concerned is email. It doesn't even take time to fake one yourself.



I have made a script that will use the first name and last name from faker and add a random number between 1 and 1000, put them together to make a fake generated email with a number to make it look more legit (Example IanCartwright268@gmail.co.uk), here is the code


from faker import Faker # Import Faker And Random For The Random Number #
from random import *
fake = Faker('en_GB') # Sets Faker's Location To Great Britain#
fn = ((fake.first_name())) # Makes The First Name Into A Veriable #
ln = ((fake.last_name())) # Makes The Last Name Into A Veriable #
rn = str (randint(1,1000)) # Makes A Random Number From 1 To 1000 And It Used To Add A Random Number To The End Of The Email To Make It Look Legit #
email = (fn + ln + rn + "@gmail.co.uk") # Adds The First Name, Last Name And The Random Number And The Extension '@gmail.co.uk' #
print("First Name: " + fn + "n" + "last Name: " + ln + "n" + "Email: " + email) # Prints The Whole Output#



I Hope This Helps, If You Need Any More Help Message Me On Twitter @R00T_H4X0R






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived