-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use static RandomValueGenerator (#22)
- Loading branch information
Showing
15 changed files
with
119 additions
and
76 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<LangVersion>10.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\ConsoleAppClassic\MainTest.cs" Link="MainTest.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RandomDataGenerator\RandomDataGenerator.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using ConsoleAppClassic; | ||
|
||
namespace ConsoleAppNetCoreApp2; | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
MainTest.Run(); | ||
} | ||
} |
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
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
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
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
9 changes: 4 additions & 5 deletions
9
src/RandomDataGenerator/Generators/RandomStringFromListGenerator.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace RandomDataGenerator.Generators | ||
namespace RandomDataGenerator.Generators; | ||
|
||
internal class RandomStringFromListGenerator : RandomItemFromListGenerator<string> | ||
{ | ||
internal class RandomStringFromListGenerator : RandomItemFromListGenerator<string> | ||
public RandomStringFromListGenerator(IEnumerable<string> list, int? seed = null) : base(seed, list) | ||
{ | ||
public RandomStringFromListGenerator(IEnumerable<string> list, int? seed = null) : base(seed, list) | ||
{ | ||
} | ||
} | ||
} |
9 changes: 4 additions & 5 deletions
9
src/RandomDataGenerator/Generators/RandomStringsFromListGenerator.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace RandomDataGenerator.Generators | ||
namespace RandomDataGenerator.Generators; | ||
|
||
internal class RandomStringsFromListGenerator : RandomItemsFromListGenerator<string> | ||
{ | ||
internal class RandomStringsFromListGenerator : RandomItemsFromListGenerator<string> | ||
public RandomStringsFromListGenerator(IEnumerable<string> list, int? seed = null) : base(seed, list) | ||
{ | ||
public RandomStringsFromListGenerator(IEnumerable<string> list, int? seed = null) : base(seed, list) | ||
{ | ||
} | ||
} | ||
} |
31 changes: 14 additions & 17 deletions
31
src/RandomDataGenerator/Generators/RandomThingsGenerator.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
using System; | ||
namespace RandomDataGenerator.Generators; | ||
|
||
namespace RandomDataGenerator.Generators | ||
internal class RandomThingsGenerator<T> | ||
{ | ||
internal class RandomThingsGenerator<T> | ||
{ | ||
private readonly RandomValueGenerator _randomValueGenerator; | ||
private readonly T _min; | ||
private readonly T _max; | ||
private readonly RandomValueGenerator _randomValueGenerator; | ||
private readonly T _min; | ||
private readonly T _max; | ||
|
||
public RandomThingsGenerator(T min, T max, int? seed) | ||
{ | ||
_min = min; | ||
_max = max; | ||
_randomValueGenerator = new RandomValueGenerator(seed ?? Environment.TickCount); | ||
} | ||
public RandomThingsGenerator(T min, T max, int? seed) | ||
{ | ||
_min = min; | ||
_max = max; | ||
_randomValueGenerator = RandomValueGeneratorFactory.Create(seed); | ||
} | ||
|
||
public T Generate() | ||
{ | ||
return _randomValueGenerator.Next(_min, _max); | ||
} | ||
public T Generate() | ||
{ | ||
return _randomValueGenerator.Next(_min, _max); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/RandomDataGenerator/Generators/RandomValueGeneratorFactory.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace RandomDataGenerator.Generators; | ||
|
||
internal static class RandomValueGeneratorFactory | ||
{ | ||
private static readonly RandomValueGenerator Value = new(Environment.TickCount); | ||
|
||
public static RandomValueGenerator Create(int? seed) | ||
{ | ||
return seed is null ? Value : new RandomValueGenerator(seed.Value); | ||
} | ||
} |
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
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
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
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