diff --git a/ARKBreedingStats/NamePatterns/NamePattern.cs b/ARKBreedingStats/NamePatterns/NamePattern.cs
index f9844ff3..3bc64761 100644
--- a/ARKBreedingStats/NamePatterns/NamePattern.cs
+++ b/ARKBreedingStats/NamePatterns/NamePattern.cs
@@ -16,6 +16,8 @@ public static class NamePattern
///
private const string PipeEscapeSequence = @"\pipe";
+ public static Random Random = new Random();
+
///
/// Generate a creature name with the naming pattern.
///
@@ -203,9 +205,6 @@ public static Dictionary CreateTokenDictionary(Creature creature
double imp = creature.imprintingBonus * 100;
double eff = creature.tamingEff * 100;
- Random rand = new Random(DateTime.Now.Millisecond);
- string randStr = rand.Next(0, 999999).ToString("000000");
-
string effImp = "Z";
string prefix = string.Empty;
if (creature.isBred)
@@ -332,7 +331,7 @@ public static Dictionary CreateTokenDictionary(Creature creature
{ "genn", (speciesCreatures?.Count(c=>c.generation==generation) ?? 0 + 1).ToString()},
{ "nr_in_gen", nrInGeneration.ToString()},
{ "nr_in_gen_sex", nrInGenerationAndSameSex.ToString()},
- { "rnd", randStr },
+ { "rnd", Random.Next(0, 999999).ToString("000000")},
{ "ln", libraryCreatureCount.ToString()},
{ "tn", speciesCount.ToString()},
{ "sn", speciesSexCount.ToString()},
diff --git a/ARKBreedingStats/NamePatterns/NamePatternFunctions.cs b/ARKBreedingStats/NamePatterns/NamePatternFunctions.cs
index efa45ff7..da7579d6 100644
--- a/ARKBreedingStats/NamePatterns/NamePatternFunctions.cs
+++ b/ARKBreedingStats/NamePatterns/NamePatternFunctions.cs
@@ -51,6 +51,7 @@ private static string ParametersInvalid(string specificError, string expression,
{"float_div", FunctionFloatDiv},
{"div", FunctionDiv},
{"casing", FunctionCasing},
+ {"rand", FunctionRand },
{"replace", FunctionReplace},
{"regexreplace", FunctionRegExReplace},
{"customreplace", FunctionCustomReplace},
@@ -247,6 +248,20 @@ private static string FunctionCasing(Match m, NamePatternParameters p)
return ParametersInvalid($"casing expects 'U', 'L' or 'T', given is '{m.Groups[3].Value}'", m.Groups[0].Value, p.DisplayError);
}
+ private static string FunctionRand(Match m, NamePatternParameters p)
+ {
+ // parameter: 1: to (if one parameter), from (if two parameters), 2: to
+ // to is exclusive
+ int.TryParse(m.Groups[2].Value, out var from);
+ if (!int.TryParse(m.Groups[3].Value, out var to))
+ {
+ to = from;
+ from = 0;
+ }
+ if (from < 0 || from >= to) return string.Empty;
+ return NamePattern.Random.Next(from, to).ToString();
+ }
+
private static string FunctionReplace(Match m, NamePatternParameters p)
{
// parameter: 1: replace, 2: text, 3: find, 4: replace
diff --git a/ARKBreedingStats/NamePatterns/PatternEditor.cs b/ARKBreedingStats/NamePatterns/PatternEditor.cs
index 0e76df89..d2094323 100644
--- a/ARKBreedingStats/NamePatterns/PatternEditor.cs
+++ b/ARKBreedingStats/NamePatterns/PatternEditor.cs
@@ -527,6 +527,7 @@ private void InsertText(string text)
{"expr", "{{#expr: expression }}, simple calculation with two operands and one operator. Possible operators are +, -, *, /.\n{{#expr: {hp} * 2 }}" },
{"len", "{{#len: string }}, returns the length of the passed string.\n{{#len: {isTophp}{isTopdm}{isTopwe} }}" },
{"substring","{{#substring: text | start | length }}. Length can be omitted. If start is negative it takes the characters from the end. If length is negative it takes the characters until that position from the end\n{{#substring: {species} | 0 | 4 }}"},
+ {"rand","{{#rand: min | max (exclusive) }} or {{#rand: max (exclusive) }}\n{{#rand: 100 }}"},
{"replace","{{#replace: text | find | replaceBy }}\n{{#replace: {species} | Aberrant | Ab }}"},
{"regexreplace","{{#regexreplace: text | pattern | replaceBy }}\nUse &{ instead {, &&vline; instead | and &} instead of }.\n{{#regexreplace: hp-st-we- | \\-$ | }}"},
{"customreplace","{{#customreplace: text }}. Replaces the text with a value saved in the file customReplacings.json.\nIf a second parameter is given, that is returned if the key is not available.\n{{#customreplace: {species} }}"},