From 1c8396efd77e792c839cb435a3adff46feed7cd1 Mon Sep 17 00:00:00 2001 From: Carl Johnsen Date: Tue, 18 Feb 2025 09:39:57 +0100 Subject: [PATCH] Add random seed option to test data generation command --- Tools/TestDataGenerator/Commands/Create.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Tools/TestDataGenerator/Commands/Create.cs b/Tools/TestDataGenerator/Commands/Create.cs index 4eed98130..de576d996 100644 --- a/Tools/TestDataGenerator/Commands/Create.cs +++ b/Tools/TestDataGenerator/Commands/Create.cs @@ -22,6 +22,7 @@ public static class Create /// The maximum depth of subfolders to create in the target folder /// The maximum number of folders to create in the target folder /// The maximum length of each path segment in the target folder + /// The random seed to use for generating the test data record CommandInput( DirectoryInfo TargetFolder, int FileCount, @@ -32,7 +33,8 @@ public static class Create int MaxFanOut, int MaxDepth, int MaxFolderCount, - int MaxPathSegmentLength); + int MaxPathSegmentLength, + string RandomSeed); /// /// Creates the command @@ -82,6 +84,10 @@ public static class Create maxPathSegmentLengthOption.SetDefaultValue(15); command.AddOption(maxPathSegmentLengthOption); + var randomSeedOption = new Option("--random-seed", "The random seed to use for generating the test data"); + randomSeedOption.SetDefaultValue("Duplicati"); + command.AddOption(randomSeedOption); + command.Handler = CommandHandler.Create(Execute); return command; @@ -121,7 +127,7 @@ public static class Create throw new Exception("The maximum path segment length must be greater than zero"); Console.WriteLine($"Creating test data in {input.TargetFolder.FullName}"); - var rnd = new Random(); + var rnd = new Random(input.RandomSeed.GetHashCode()); var folders = GeneratePathStructure(rnd, input.TargetFolder.FullName, input.MaxDepth, input.MaxFanOut, input.MaxPathSegmentLength); while (folders.Count < input.MaxFolderCount) {