Random Nonsense Word Generator

As I went to sleep last night I was wondering how I could create some random word-like words, for something I’ve been working on. When I woke up, I had the solution! So, I thought I’d share how I did it.

The thing that was bothering me was where to find a list of dictionary words to look at to generate a nonsensical, but ‘word-like’ part of a word. I started thinking about dictionary.com and if they had some kind of API, amaong others.

Then it occurred to me that most Linux distros have a dictionary built in to the system. It lives at /usr/share/dict/words

So, with a little snippet of PHP, I was able to look at a part of this file and grab some characters.

here it is:

function makeNonsense($length){

        // used to create word fragments $length long

        $dictionaryFile = "/usr/share/dict/words";
        // eventually need to make this go higher than the rand max 32768
        $content=file_get_contents($dictionaryFile,FALSE,NULL,rand(0,32768),$length);
        // get rid of numbers. spaces and other characters
        $content = ereg_replace("[^a-zA-Z]", "", $content);
        $content = strtolower(str_replace(" ","",$content));
        $nonsense = str_replace("\n","",$content);
        return $nonsense;

}

And that’s it! ;)

2 Responses to “Random Nonsense Word Generator”


  1. 1 Leif August 15, 2008 at 8:44 am

    Interesting… could this be turned into a WordPress plugin that generates random words?

    I’d really like a thingamyjig on my blog that features one word, randomly generated when viewed. The words could be anything (no swears though). So words like ‘flan’, ‘fajita’, ‘cajole’ and ’spackle’ are all fine.

  2. 2 kosso September 15, 2008 at 1:52 am

    I don’t see any reason why not.

    It all depends on the word file. You could use any body of text though, I suppose ;)


Leave a Reply




 

April 2008
M T W T F S S
« Jan   May »
 123456
78910111213
14151617181920
21222324252627
282930  

Who is this ‘kosso’ anyway?

I am a 'Createc'. A creative technologist, entrepreneur/ hacker/ geek. Worked on building things on the web for over 12 years.

Used to work at BBC News interactive and created the publishing and delivery systems for video news to get distributed on huge screens in major railway stations around the country.

I left the BBC to become CTO / sole-lead architect/developer at podcast.com for three years.

I have now left them to build a start up a new system called 'Phreadz', which is a 'Social Multimedia Conversation Network', integrating everything that is 'V.I.T.A.L' to us on the web. Video, Images, Text, Audio and Links.

I built the whole thing my myself and will soon be looking for funds to expand the team and system to make it available to launch.

There are currently happy and helpful 500 (closed) beta testers on the system so far and one client of a white-labelled solution.

Phreadz has a business model, which is already working.

kosso's flickr stream

another File2Mail test

Not impressed  kz

At the Ferry Building

Digital Teen

Bobby!

some young turks! ;)

Yeovil Town

on the road

The "Twisto" posse

IMG_1965.JPG

More Photos

RSS me and my twitters

  • An error has occurred; the feed is probably down. Try again later.

About kosso

I'm currently the CTO at podcast.com - ex-BBC News interactive. Love gadgets. Loves to makes tools for gadgets. In love with building on the web for over a decade.

stats

  • 164,608