Skip to content

Instantly share code, notes, and snippets.

@brandedoutcast
Created January 27, 2018 03:51
Show Gist options
  • Save brandedoutcast/a701b6222f7858497ee386e082bdf04f to your computer and use it in GitHub Desktop.
Save brandedoutcast/a701b6222f7858497ee386e082bdf04f to your computer and use it in GitHub Desktop.
Generate random words & dates
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models
{
public class Text
{
static Random Rand = new Random();
public static string GetRandomWords(short Count)
{
return GenerateRandomWords(1);
}
public static string GetRandomWords(short MinCount, short MaxCount)
{
return GenerateRandomWords(Rand.Next(MinCount, MaxCount));
}
private static string GenerateRandomWords(int SentenceCount)
{
StringBuilder Sb = new StringBuilder();
for (int i = 0; i < SentenceCount; i++)
{
int WordCount = Rand.Next(3, 10);
for (int j = 0; j < WordCount; j++)
Sb.Append(char.ConvertFromUtf32(Rand.Next(97, 123)));
Sb.Append(" ");
}
return Sb.ToString();
}
public static IEnumerable<DateTime> GetRandomDates(short Count, DateTime RangeStartDate, DateTime RangeEndDate)
{
if (Count < 1)
return null;
int Range = (RangeEndDate - RangeStartDate).Days;
List<DateTime> Dates = new List<DateTime>();
Random Rand = new Random();
for (short i = 0; i < Count; i++)
Dates.Add(RangeStartDate.AddDays(Rand.Next(0, Range)));
return from d in Dates
select d;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment