Created
October 19, 2023 13:58
-
-
Save lesutton/54682904a33a005339760f445e85ae02 to your computer and use it in GitHub Desktop.
Python 75kb Sample File Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
text = "A" * 76000 # This will generate a string with 75,000 "A" characters | |
# Save to a file | |
with open("75KB_text.txt", "w") as file: | |
file.write(text) | |
import json | |
# Estimate the number of records needed for 75KB based on the rough size of one record. | |
# This is an approximation. Adjust as needed. | |
num_records = 1480 | |
data = [{"id": i, "name": f"Item {i}"} for i in range(num_records)] | |
# Save the data to a JSON file with indentation for better readability | |
with open("75KB_data.json", "w") as f: | |
json.dump(data, f, indent=2) | |
# Number of records estimated to generate a file close to 75KB | |
# This is an approximation based on a rough size of one record. | |
# Adjust as needed. | |
num_records = 4900 | |
header = "id,name\n" | |
# Generate the data rows | |
rows = [f"{i},Item {i}\n" for i in range(1, num_records + 1)] | |
# Concatenate header and rows | |
content = header + "".join(rows) | |
# Save the content to a file | |
with open("75KB_data.csv", "w") as f: | |
f.write(content) | |
import random | |
import string | |
# Target size is 75KB, which is roughly 75,000 characters | |
TARGET_SIZE = 75500 | |
# Possible characters to use in our random text | |
CHARS = string.ascii_letters + string.digits + string.punctuation + string.whitespace | |
def generate_random_text(target_size): | |
return ''.join(random.choice(CHARS) for _ in range(target_size)) | |
random_text = generate_random_text(TARGET_SIZE) | |
# Save the random text to a file | |
with open("75KB_random_text.txt", "w") as file: | |
file.write(random_text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment