@@ -50,6 +50,8 @@ def generate_uuid(amount: int = 1, version: int = 4, namespace: uuid.UUID = uuid
50
50
:return: List of generated UUIDs.
51
51
:raises ValueError: If an invalid UUID version is provided or required arguments are missing.
52
52
"""
53
+ if version not in [1 , 3 , 4 , 5 ]:
54
+ raise ValueError ("Invalid UUID version. Use 1, 3, 4, or 5." )
53
55
if version in [3 , 5 ] and (namespace is None or name is None ):
54
56
raise ValueError (f"UUID version { version } requires 'namespace' and 'name' arguments" )
55
57
uuid_func = {
@@ -96,7 +98,7 @@ def digits_of(n):
96
98
return checksum % 10
97
99
98
100
@classmethod
99
- def __generate_luhn_compliant_number (cls , length : int ) -> str :
101
+ def __generate_compliant_number (cls , length : int ) -> str :
100
102
"""
101
103
Generate a Luhn-compliant card number of a specified length.
102
104
@@ -118,7 +120,7 @@ def credit_card(cls, amount: int = 1) -> list[dict[str, str]]:
118
120
"""
119
121
credit_cards = []
120
122
for _ in range (amount ):
121
- credit_card_number = cls .__generate_luhn_compliant_number (16 )
123
+ credit_card_number = cls .__generate_compliant_number (16 )
122
124
cvv = '' .join (random .choices (string .digits , k = 3 ))
123
125
expiration_date = f"{ random .randint (1 , 12 ):02d} /{ random .randint (22 , 30 ):02d} "
124
126
credit_cards .append ({
@@ -176,6 +178,9 @@ def name(cls, format: str = None, amount: int = 1) -> list[str]:
176
178
"""
177
179
Generate a list of random names.
178
180
181
+ Format string can contain {first_name} and {last_name} placeholders.
182
+ Example format: "{first_name} {last_name}".
183
+
179
184
:param format: Optional format string for the names, using {first_name} and {last_name} as placeholders.
180
185
:param amount: Number of names to generate.
181
186
:return: List of generated names.
@@ -190,6 +195,9 @@ def address(cls, format: str = None, amount: int = 1) -> list[str]:
190
195
"""
191
196
Generate a list of random addresses.
192
197
198
+ Format string can contain {street_address}, {city}, {country}, and {postal_code} placeholders.
199
+ Example format: "{street_address}, {city}, {country} {postal_code}".
200
+
193
201
:param format: Optional format string for the addresses, using {street_address}, {city}, {country}, and {postal_code} as placeholders.
194
202
:param amount: Number of addresses to generate.
195
203
:return: List of generated addresses.
@@ -223,6 +231,9 @@ def phone_number(format: str = None, amount: int = 1) -> list[str]:
223
231
"""
224
232
Generate a list of random phone numbers.
225
233
234
+ Format string can contain {phone_number} as a placeholder.
235
+ Example format: "John's phone number is {phone_number}".
236
+
226
237
:param format: Optional format string for the phone numbers, using {phone_number} as a placeholder.
227
238
:param amount: Number of phone numbers to generate.
228
239
:return: List of generated phone numbers.
@@ -236,6 +247,9 @@ def email(cls, format: str = None, amount: int = 1) -> list[str]:
236
247
"""
237
248
Generate a list of random email addresses.
238
249
250
+ Format string can contain {email} as a placeholder.
251
+ Example format: "John's email is {email}"
252
+
239
253
:param format: Optional format string for the email addresses, using {email} as a placeholder.
240
254
:param amount: Number of email addresses to generate.
241
255
:return: List of generated email addresses.
@@ -251,6 +265,9 @@ def date(format: str = None, amount: int = 1) -> list[str]:
251
265
"""
252
266
Generate a list of random dates.
253
267
268
+ Format string should be in the strftime format.
269
+ Example format: "%Y-%m-%d".
270
+
254
271
:param format: Optional format string for the dates.
255
272
:param amount: Number of dates to generate.
256
273
:return: List of generated dates.
@@ -302,7 +319,7 @@ def job_title(cls, amount: int = 1) -> list[str]:
302
319
return [str (random .choice (cls .job_titles )) for _ in range (amount )]
303
320
304
321
@staticmethod
305
- def employee_id (amount : int = 1 , characters_to_use : str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ) -> list [str ]:
322
+ def employee_id (amount : int = 1 , characters_to_use : str = ( string . ascii_uppercase + string . digits ) ) -> list [str ]:
306
323
"""
307
324
Generate a list of random employee IDs.
308
325
@@ -376,13 +393,14 @@ def __init__(cls, extra_domains: list = None):
376
393
377
394
:param extra_domains: List of additional domains to include.
378
395
"""
379
- cls .domains = ["example.com" , "test.com" , "sample.org" , "demo.net" ]
396
+ cls .domains = ["example.com" , "test.com" , "sample.org" , "demo.net" , "fake.com" ,
397
+ "mock.org" , "example.net" , "test.org" , "sample.com" , "demo.net" ]
380
398
if extra_domains :
381
399
cls .domains .extend (extra_domains )
382
400
383
401
@staticmethod
384
402
def generate_username (amount : int = 1 , size : int = 8 ,
385
- charset : str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-<>?!@#$%^&*()[]{};=-_" ) -> list [str ]:
403
+ charset : str = string . ascii_letters ) -> list [str ]:
386
404
"""
387
405
Generate a list of random usernames.
388
406
@@ -395,7 +413,7 @@ def generate_username(amount: int = 1, size: int = 8,
395
413
396
414
@staticmethod
397
415
def generate_password (amount : int = 1 , size : int = 12 ,
398
- charset : str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-<>?!@#$%^&*()[]{};=-_" ) -> list [str ]:
416
+ charset : str = ( string . ascii_letters + string . digits + string . punctuation ) ) -> list [str ]:
399
417
"""
400
418
Generate a list of random passwords.
401
419
@@ -421,13 +439,18 @@ def generate_ip_address(amount: int = 1, version=4) -> list[str]:
421
439
ip_addresses .append ('.' .join (str (random .randint (0 , 255 )) for _ in range (4 )))
422
440
elif version == 6 :
423
441
ip_addresses .append (':' .join ('' .join (random .choices ('0123456789abcdef' , k = 4 )) for _ in range (8 )))
442
+ else :
443
+ raise ValueError ("Invalid IP version. Use 4 or 6." )
424
444
return ip_addresses
425
445
426
446
@classmethod
427
447
def generate_url (cls , amount : int = 1 , format : str = None ) -> list [str ]:
428
448
"""
429
449
Generate a list of random URLs.
430
450
451
+ Format string can contain {domain} and {path} placeholders.
452
+ Example format: "https://{domain}/{path}".
453
+
431
454
:param amount: Number of URLs to generate.
432
455
:param format: Optional format string for the URLs, using {domain} and {path} as placeholders.
433
456
:return: List of generated URLs.
0 commit comments