C# Method not returning a unique value when it should be.
- by Josh King
I have two methods, generateNounPhrase() and generateVerbPhrase(). VerbPhrase will call on NounPhrase half the time and it's output the output should be something to the effect of:
the empty lot re-animates this pyramid
(bold indicating where generateNounPhrase() is logically called). The true output however is in the form of:
the empty lot re-animates the empty lot
At first I thought my randomIndex method wasn't working as I had intended, but if I run the two methods again I do get different noun phrases but they are not unique at the beginning and end of the sentence as they should be.
Any idea what I am doing wrong in order to get one method to show the same result?
private string generateNounPhrase()
{
string nounPhraseString = "";
nounPhraseString = nounMarkersStringList[randomIndex(0,nounMarkersStringList.Count-1)];
if (included(1, 4, 2) == true)
{
nounPhraseString += " " + adjectivesStringList[randomIndex(0, adjectivesStringList.Count - 1)];
}
nounPhraseString += " " + nounsStringList[randomIndex(0, nounsStringList.Count - 1)];
return nounPhraseString;
}
private string generateVerbPhrase()
{
string verbPhraseString = "";
if (included(1, 4, 2) == true)
{
verbPhraseString = intransitiveVerbsStringList[randomIndex(0, intransitiveVerbsStringList.Count - 1)];
}
else
{
verbPhraseString = transitiveVerbsStringList[randomIndex(0, transitiveVerbsStringList.Count - 1)] + " " + generateNounPhrase();
}
return verbPhraseString;
}