//Add the chars in alphabet from start to end to the set internal void AddRange(char start, char end) { RENode.AssertParse((start < end) && end <= char.MaxValue, "Invalid range specified in char set"); if (end > mMapSize) { ExpandToUnicodeRange(); } //mark the added characters and update the number of available choices for (long c = start; c <= end; c++) { if (mMap[c] == 0) { mMap[c] = 1; mNumChoices += mPositiveSet ? 1 : -1; } } //check if this set still has invalid characters available if ((mPositiveSet && mNumChoices == mMapSize) || (!mPositiveSet && mNumChoices == 0)) { //can never be invalid RECompiler.InvalidableNodes.Remove(this); } }
internal override string Generate(Random random) { if (this == RECompiler.InvalidNode) { RENode.AssertParse(mNumChoices > 0, "No valid range specified in char set"); //select from the elements that are not available (elements that are invalid) int randIndex = random.Next(mMapSize - mNumChoices); int i = -1; while (randIndex >= 0) //seek to the available element { i++; //invert positive and negative sets if ((mPositiveSet && mMap[i] == 0) || (!mPositiveSet && mMap[i] == 1)) { randIndex--; } } return(Convert.ToChar(i).ToString()); } else { RENode.AssertParse(mNumChoices > 0, "No valid range specified in char set"); //select from the elements that are available int randIndex = random.Next(mNumChoices); int i = -1; while (randIndex >= 0) //seek to the available element { i++; if ((mPositiveSet && mMap[i] == 1) || (!mPositiveSet && mMap[i] == 0)) { randIndex--; } } return(Convert.ToChar(i).ToString()); } }