OK, the title was a little misleading as I didn't know what to put, but basically the other day slightly tipsy and have A.I ideas floating around in my head, I decided, what if I run a program through random code to come up with legitimate words in English, then laughing to myself imagining scary results like "You will die in october" or something of that ilk, so I got to it. As a way for the program to understand what it a legitimate English word I downloaded a local text file and created the code.
It does this:
Loads the dictionary into memory
uses alphabetical characters a - z
runs a constant loop creating a random feed
generates a word size between 1 and 35 characters long
then, word size dependant, creates a random alphabetical character for each letter in the word
then, it compares the generated word to the dictionary, if it's valid, a log will be made (with time/date stamp) and continue, if not it'll just continue
Now, I am sure there are better ways to make this but I was tipsy when I coded it, I ran it through about 70,000,000 attempts and nothing! but, while statistically you may have more chance winning the lottery, it's still possibly to come up with a word, or several for that matter and I think it would be interested what the program/computer could say from completely randomly generated code.
I've zipped up the executable with dict
http://www.filedropper.com/wordgenbycraigfox, please run it and give it a shot, could be interested results.
Let me know what you think, feel free to also make suggestions/improvements.
Code below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Media;
namespace AI_word_gen
{
class Program
{
static void Main(string[] args)
{
//---------------Load dict into mem------------------------------------
string dictionary = File.ReadAllText("wordsEn.txt");
//---------------------generate random words---------------------------
char[] alphabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
int attempts = 0;
while (true)
{
string sWord = " ";
//random feed
Random rnd = new Random();
//generate a word size between 1 - 35
int iwordSize = rnd.Next(1, 35);
//perform a loop from word size generating a random alphabetical charater each iteration
for (int i = 0; i < iwordSize; i++)
{
int irandLetter = rnd.Next(1, 26);
sWord += alphabet[irandLetter];
} sWord += " ";
//--------------------compare words-------------------------------------
if (dictionary.Contains(sWord))
{
Console.WriteLine("Found: " + sWord + "on: " + DateTime.Now.ToString("dd-MM-yyyy @ HH:mm"));
System.IO.StreamWriter file = new System.IO.StreamWriter("results.txt");
file.WriteLine("Found: " + sWord + "on: " + DateTime.Now.ToString("dd-MM-yyyy @ HH:mm"));
file.Close();
}
Console.Title = "Attempts = " + attempts++ + " word = " + sWord;
}
Console.WriteLine("\nFINISHED");
Console.ReadLine();
}
}
}