Ejemplo n.º 1
0
		public string Generate(StringGeneratorSettings settings, int length)
		{
			return Generate(settings, new Range<int>(_defaultLenghtRange.From, length));
		}
Ejemplo n.º 2
0
		public string Generate(StringGeneratorSettings settings, Range<int> rangeLength)
		{
			var random = CreateRandom();

			var result = string.Empty;

			var actualLength = new Range<int>(1, rangeLength.To);

			if (settings.HasFlag(StringGeneratorSettings.RandomLength))
			{
				//actualLength.From = random.Next(rangeLength.From, rangeLength.To - 1);

				actualLength.To = random.Next(rangeLength.From, rangeLength.To);
			}
			var actions = new List<StringGeneratorSettings>();

			if (settings.HasFlag(StringGeneratorSettings.Latin))
			{
				actions.Add(StringGeneratorSettings.Latin);
			}
			if (settings.HasFlag(StringGeneratorSettings.Cyrillic))
			{
				actions.Add(StringGeneratorSettings.Cyrillic);
			}
			if (settings.HasFlag(StringGeneratorSettings.Number))
			{
				actions.Add(StringGeneratorSettings.Number);
			}
			if (settings.HasFlag(StringGeneratorSettings.Space))
			{
				actions.Add(StringGeneratorSettings.Space);
			}
			var actionsCount = actions.Count;

			for (var i = actualLength.From; i <= actualLength.To; i++)
			{
				switch (actions[random.Next(0, actionsCount)])
				{
					case StringGeneratorSettings.Latin:
						var latinRange = (settings.HasFlag(StringGeneratorSettings.Caps) && random.Next(0, 9) > 5) ? _latinCapsRange : _latinLowerRange;

						result += (char)random.Next(latinRange.From, latinRange.To);
						break;
					case StringGeneratorSettings.Cyrillic:
						var cyrillicRange = (settings.HasFlag(StringGeneratorSettings.Caps) && random.Next(0, 9) > 5) ? _cyrillicCapsRange : _cyrillicLowerRange;

						result += (char)random.Next(cyrillicRange.From, cyrillicRange.To);
						break;
					case StringGeneratorSettings.Number:
						result += random.Next(0, 9).ToString();
						break;
					case StringGeneratorSettings.Space:
						var aRange = (settings.HasFlag(StringGeneratorSettings.Cyrillic)) ? _cyrillicLowerRange : _latinLowerRange;
						result += (result.Length <= 0 || i == actualLength.To - 1) ? (char)random.Next(aRange.From, aRange.To) : ' ';
						break;
					default:
						result += (char)random.Next(_latinLowerRange.From, _latinLowerRange.To);
						break;
				}
			}
			return result;
		}
Ejemplo n.º 3
0
		public string Generate(StringGeneratorSettings settings)
		{
			return Generate(settings, _defaultLenghtRange);
		}