Mock Data Generator
Generate realistic fake data for testing and development.
150100
Sıkça Sorulan Sorular
Kod Uygulaması
import random
import uuid
import json
FIRST_NAMES = ["Alice", "Bob", "Carol", "David", "Emma", "Frank", "Grace", "Henry"]
LAST_NAMES = ["Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller"]
CITIES = ["New York", "London", "Tokyo", "Paris", "Berlin", "Seoul", "Sydney"]
COUNTRIES = ["USA", "UK", "Japan", "France", "Germany", "South Korea", "Australia"]
DOMAINS = ["gmail.com", "yahoo.com", "outlook.com", "example.com"]
COMPANIES = ["Acme Corp", "Globex", "Initech", "Hooli", "Dunder Mifflin"]
def generate_record(fields: list[str]) -> dict:
fn = random.choice(FIRST_NAMES)
ln = random.choice(LAST_NAMES)
record = {}
for field in fields:
if field == "firstName": record["firstName"] = fn
elif field == "lastName": record["lastName"] = ln
elif field == "email": record["email"] = f"{fn.lower()}.{ln.lower()}@{random.choice(DOMAINS)}"
elif field == "phone": record["phone"] = f"+1-{random.randint(200,999)}-{random.randint(100,999)}-{random.randint(1000,9999)}"
elif field == "city": record["city"] = random.choice(CITIES)
elif field == "country": record["country"] = random.choice(COUNTRIES)
elif field == "age": record["age"] = random.randint(18, 80)
elif field == "uuid": record["uuid"] = str(uuid.uuid4())
elif field == "company": record["company"] = random.choice(COMPANIES)
return record
# Generate 10 records with name and email
fields = ["firstName", "lastName", "email", "age", "city"]
data = [generate_record(fields) for _ in range(10)]
print(json.dumps(data, indent=2))Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.