Here is an example of a "nickname generator":
First let's create a couple of tables:
CREATE TABLE ADJECTIVES(Then fill the tables with some value
CREATE TABLE ANIMALS(
INSERT INTO ADJECTIVES VALUES('Lazy');To implement the selection we can use MySQL RAND() function. Rand function can generate a pseudo-random number sequence based on a seed integer passed as parameter. The same seed number ever generates the same sequence.
INSERT INTO ADJECTIVES VALUES('Fat');
INSERT INTO ADJECTIVES VALUES('Crazy');
INSERT INTO ADJECTIVES VALUES('Ugly');
INSERT INTO ANIMALS VALUES('Bull');
INSERT INTO ANIMALS VALUES('Cow');
INSERT INTO ANIMALS VALUES('Monkey');
INSERT INTO ANIMALS VALUES('Chicken');
Another function HEX() let us easily convert our input string to a number we can use as seed.
The number generated from RAND() function can eventually be used to select a row in the table.
Let's put all together:
SELECT(Update) since RAND() ever generates the same number sequence from the same seed number we must use a different seed for every word we need to extract. To do this we neeed to change the source string in order to obtain a different seed number. In my example I used the REVERSE() function to implement it (not the best choice indeed) but even simpler solutions, like adding a different constant to each, should work also well.
(SELECT TERM FROM ADJECTIVES ORDER BY RAND(HEX('musante.i.ph')) LIMIT 1) AS Adjective,
(SELECT NAME FROM ANIMALS ORDER BY RAND(HEX(REVERSE('musante.i.ph'))) LIMIT 1) AS Animal;
Here is the result:
Adjective Animal Crazy Chicken
Does it fit with my blog? Probably no more than "Ultimate Monk"!
What makes the difference, in this kind of programs, is the database of names used. A wider database generates, of course , a less repetitive set of phrases but what really matters is a good choice of the words database.