nameyourpet Posted April 24, 2007 Share Posted April 24, 2007 Hey I really need some help, does anyone have a piece of code, which randomly generates a word? For example, when you click on a link called say... Random Name, it will come up with a name, either Paul, Luke, John or Terry (but only one of them, so eventually I can have loads so it goes on and on...) Get what i mean? If you're wondering why I need this, it because I'm making a website where you can choose a type of pet and then click on 'Gimme A Hamster Name' and it will come up with a hamster's name. I'll be very happy if anyone can help Ollie Link to comment https://forums.phpfreaks.com/topic/48512-random-word-generation-from-a-selection-of-words/ Share on other sites More sharing options...
Mr. R Posted April 24, 2007 Share Posted April 24, 2007 try this.. EDIT sorry that doesnt work.. try this.. <?php $names = array("john","paul","charles","bob","bill"); $rand_keys=array_rand($names,2); echo "random name = ".$names[$rand_keys[0]]; ?> Link to comment https://forums.phpfreaks.com/topic/48512-random-word-generation-from-a-selection-of-words/#findComment-237344 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 Or you could have a list of names in a database, generate a random number upto the number of rows in the database, then print the name of that row, easier to add new names via a database than via adding them to an array Link to comment https://forums.phpfreaks.com/topic/48512-random-word-generation-from-a-selection-of-words/#findComment-237355 Share on other sites More sharing options...
nameyourpet Posted April 25, 2007 Author Share Posted April 25, 2007 Thank Your Link to comment https://forums.phpfreaks.com/topic/48512-random-word-generation-from-a-selection-of-words/#findComment-238181 Share on other sites More sharing options...
johncccccc Posted July 14, 2010 Share Posted July 14, 2010 Hi, sorry for bumping an old topic.. How can we pick 2 names from the list? Link to comment https://forums.phpfreaks.com/topic/48512-random-word-generation-from-a-selection-of-words/#findComment-1085670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.