Skip to content

Commit

Permalink
Merge branch 'cleanup-11-28-18'
Browse files Browse the repository at this point in the history
  • Loading branch information
clintcparker committed May 9, 2019
2 parents d1b188a + 9572c58 commit e24607b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/name-on-web/bin/Debug/netcoreapp2.1/name-on-web.dll",
"program": "${workspaceFolder}/name-on-web/bin/Debug/netcoreapp2.1/publish/name-on-web.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
Expand Down
25 changes: 14 additions & 11 deletions name-on-core/Namer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,51 @@ public class Namer
{
private static Namer Instance = new Namer();

private string lastReturn;
private string _lastReturn;

// Make sure
private static Random _random;

static Namer()
{
var d = new Dicts();
Adjectives = d.Adjectives;
Nouns = d.Nouns;
_random = new Random();
}

public string Gen()
{
// var retVal = "Test-one-123";
var retVal = Instance.GenRandomString();
while (lastReturn == retVal)
while (_lastReturn == retVal)
{
retVal = Instance.GenRandomString();
}
lastReturn = retVal;
return lastReturn;
_lastReturn = retVal;
return _lastReturn;
}



private string GenRandomString()
{
return $"{GenRandomAdjective()}-{GenRandomNoun()}-{GenRandomThreeDigits()}";
}

// TODO: keep the Random Instance as as private
private int GenRandomThreeDigits()
{
var r = new Random();
return r.Next(0,999);
return _random.Next(0,999);
}

private string GenRandomNoun()
{
var r = new Random();
return Nouns[r.Next(0,Nouns.Count-1)];
return Nouns[_random.Next(0,Nouns.Count-1)];
}

private string GenRandomAdjective()
{
var r = new Random();
return Adjectives[r.Next(0,Adjectives.Count-1)];
return Adjectives[_random.Next(0,Adjectives.Count-1)];
}

private static List<string> Adjectives;
Expand Down

0 comments on commit e24607b

Please sign in to comment.