Created
November 12, 2021 06:04
-
-
Save mafshin/ee3d9746fc5bcee35603d7becd7c3407 to your computer and use it in GitHub Desktop.
Sample Data Generator for Task #1 (.NET 6)
This file contains hidden or 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
// See https://aka.ms/new-console-template for more information | |
int count = 6; | |
var products = Enumerable.Range(1001, 20).ToArray(); | |
for (int i = 1; i <= count; i++) | |
{ | |
int recordsCount = (int)Math.Pow(10, i); | |
var fileName = $"Data/Data{recordsCount}.csv"; | |
Directory.CreateDirectory("Data"); | |
using (FileStream fs = new FileStream(fileName, FileMode.Create)) | |
{ | |
WriteRecords(fs, recordsCount); | |
} | |
Console.WriteLine($"File {fileName} is written to disk"); | |
} | |
void WriteRecords(FileStream fs, int recordsCount) | |
{ | |
using (StreamWriter sw = new StreamWriter(fs)) | |
{ | |
sw.WriteLine("RecordNumber | ProductId | Price | Quantity"); | |
for (int i = 0; i < recordsCount; i++) | |
{ | |
sw.WriteLine("{0} | {1} | {2} | {3}", | |
i + 1, | |
products[Random.Shared.Next(products.Length)], | |
Random.Shared.Next(100, 100000), | |
Random.Shared.Next(1, 1000)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment