using System.Collections.Generic;
public static void Main()
var options = new Castle.Sharp2Js.JsGeneratorOptions()
OutputNamespace = "events",
IncludeMergeFunction = false,
ClassNameConstantsToRemove = null,
RespectDataMemberAttribute = true,
RespectDefaultValueAttribute = true,
TreatEnumsAsStrings = false
Console.WriteLine(Markov("alice_oz.txt asdasd dsad asdas sdad asdsa asdsad dsad asdasd dsad", 2, 5));
static string Join(string a, string b) {
static string Markov(string filePath, int keySize, int outputSize) {
if (keySize < 1) throw new ArgumentException("Key size can't be less than 1");
var words = body.Split();
if (outputSize < keySize || words.Length < outputSize) {
throw new ArgumentException("Output size is out of range");
Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
for (int i = 0; i < words.Length - keySize; i++) {
var key = words.Skip(i).Take(keySize).Aggregate(Join);
if (i + keySize < words.Length) {
value = words[i + keySize];
if (dict.ContainsKey(key)) {
dict.Add(key, new List<string>() { value });
Random rand = new Random();
List<string> output = new List<string>();
int rn = rand.Next(dict.Count);
string prefix = dict.Keys.Skip(rn).Take(1).Single();
output.AddRange(prefix.Split());
var suffix = dict[prefix];
return output.Aggregate(Join);
rn = rand.Next(suffix.Count);
if (output.Count >= outputSize) {
return output.Take(outputSize).Aggregate(Join);
prefix = output.Skip(n).Take(keySize).Aggregate(Join);