<?php

// The following code has been released to Public Domain by its author (Juhana Leinonen).
// Kudos to David Fisher for the original algorithm and idea.



define( 'NAMES_TO_PRINT', 40 );

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
<title>
IF Name Generator
</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Pragma" content="no-cache" />

</head>

<body>

<p>
The following is a list of <?= NAMES_TO_PRINT ?> randomized IF game titles created by
joining the beginning and end parts of two random existing IF titles.
You can create a new random list by refreshing your browser (usually with the F5 key).
</p>

<p>
The original generator and algorithm was created by David Fisher,
who was inspired by the
<a href="http://www.norefuge.net/vgng/vgng.html">Video Game Name Generator</a>
and extracted the name list from <a href="http://www.wurb.com/if/">Baf's Guide</a>
(see the <a href="http://groups.google.fi/group/rec.arts.int-fiction/browse_thread/thread/4428f0f75e24abe1/">rec.arts.int-fiction thread</a>).
</p>

<div style="float:right;margin:1em;">
<a href="source.php">Source</a><br />
</div>


<pre>

<?php

// names.php contains all the game titles in an array, like so:
// $names = array(
// '\'Twas a Time of Dread',
// '(You\'re) TOAST!',
// '(untitled)',
// ... etc

include_once( 'names.php' );


// the code itself is super simple.

for( $loop = 0; $loop < NAMES_TO_PRINT; ++$loop )
{
$source = array_rand( $names, 2 );

$prefix = explode( ' ', $names[ $source[ 0 ] ] );
$suffix = explode( ' ', $names[ $source[ 1 ] ] );

$prefix_words = count( $prefix );
$suffix_words = count( $suffix );

if( $prefix_words == 1 )
{
echo $prefix[ 0 ] . ' ';
}
else
{
$prefix_pick = rand( 1, count( $prefix ) - 1 );

for( $i = 0; $i < $prefix_pick; ++$i )
{
echo $prefix[ $i ] . ' ';
}
}

if( $suffix_words == 1 )
{
echo $suffix[ 0 ] . ' ';
}
else
{
$suffix_pick = rand( 1, count( $suffix ) - 1 );

for( $i = $suffix_pick; $i < $suffix_words; ++$i )
{
echo $suffix[ $i ] . ' ';
}
}

echo "\n";

}

?>

</pre>

</body>
</html>