Skip to content

Instantly share code, notes, and snippets.

@afomi
Created November 13, 2023 23:17
Show Gist options
  • Save afomi/37d89569e5da6e79ea9555a0833e60fc to your computer and use it in GitHub Desktop.
Save afomi/37d89569e5da6e79ea9555a0833e60fc to your computer and use it in GitHub Desktop.
require 'csv'
# Define the file name
file_name = "sample_data.csv"
# Define the number of rows and columns
num_rows = 10000
num_columns = 12
# Open a CSV file for writing
CSV.open(file_name, "wb") do |csv|
# Add a header row (optional)
csv << ["Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12"]
# Generate data for each row
num_rows.times do |i|
row = Array.new(num_columns) { |index| "Data #{i+1}-#{index+1}" }
csv << row
end
end
puts "#{file_name} has been created with #{num_rows} rows and #{num_columns} columns."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment