What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » General » General Chit Chat » Random Word [site]

Random Word [site]
Author: Message:
Eddie
Veteran Member
*****


Posts: 2078
Reputation: 30
32 / Male / Flag
Joined: Oct 2005
Status: Away
O.P. Random Word [site]
Hello, on my site, im planning to host a competition where someone must find a page and submit the code on the page, is there any way in PHP or JavaScript that will allow for a random word to be placed on the page somewhere? :)
...there used to be a signature here :)
03-26-2007 08:22 AM
Profile PM Web Find Quote Report
the DtTvB
Junior Member
**


Posts: 47
Reputation: 10
– / Male / –
Joined: Mar 2007
Status: Away
RE: Random Word [site]
Yeah, you just need a dictionary.

I recommend using english-words.50 file from scowl-6.

Now you have to create an array from a file and pick a word.

Example code:
code:
<?php

$wordlist = file('english-words.50');

function pick_a_word() {
    global $wordlist;
    return trim($wordlist[rand(0, count($wordlist) - 1)]);
}

for ($i = 0; $i < 20; $i ++)
    echo pick_a_word() . ' ';

?>

This post was edited on 03-26-2007 at 09:15 AM by the DtTvB.
the DtTvB - My name has no meaning, but it's unique at least!
[Image: asj.gif]
03-26-2007 09:09 AM
Profile E-Mail PM Web Find Quote Report
Eddie
Veteran Member
*****


Posts: 2078
Reputation: 30
32 / Male / Flag
Joined: Oct 2005
Status: Away
O.P. RE: Random Word [site]
quote:
Originally posted by the DtTvB
Yeah, you just need a dictionary.

I recommend using english-words.50 file from scowl-6.

Now you have to create an array from a file and pick a word.
Will the word just automatically come up? and im not using words, just random codes *-)
...there used to be a signature here :)
03-26-2007 09:11 AM
Profile PM Web Find Quote Report
the DtTvB
Junior Member
**


Posts: 47
Reputation: 10
– / Male / –
Joined: Mar 2007
Status: Away
RE: Random Word [site]
You just have to create a list of characters [1] [2] and select it randomly.

code:
<?php

$charlist = (array_merge(
    range('0', '9'),
    range('a', 'z'),
    range('A', 'Z')
));

function pick_a_character() {
    global $charlist;
    return $charlist[rand(0, count($charlist) - 1)];
}

function create_code($length) {
    $o = '';
    for ($i = 0; $i < $length; $i ++)
        $o .= pick_a_character();
    return $o;
}

$code = create_code(12);
echo "The code is $code";

?>

This post was edited on 03-26-2007 at 09:24 AM by the DtTvB.
the DtTvB - My name has no meaning, but it's unique at least!
[Image: asj.gif]
03-26-2007 09:17 AM
Profile E-Mail PM Web Find Quote Report
Felu
Veteran Member
*****


Posts: 2223
Reputation: 72
29 / Male / Flag
Joined: Apr 2006
Status: Away
RE: Random Word [site]
As simple as
1. Create and array of words/codes
2. Loop through the array and pick up a random word/code.

I'll post the code later. I have to go atm.
03-26-2007 09:18 AM
Profile E-Mail PM Web Find Quote Report
Eddie
Veteran Member
*****


Posts: 2078
Reputation: 30
32 / Male / Flag
Joined: Oct 2005
Status: Away
O.P. RE: Random Word [site]
Ok that worked well, but i want to be able to choose wot the codes are :P
Oh and around 7 word codes only :P Sorry to be a bother :( [EDIT: Figured This Bit Out]

I know this makes it a little less random to the developer, but to the general public, its still random :P

[EDIT: Figured it out :) Thanks guys]

This post was edited on 03-26-2007 at 10:30 AM by Eddie.
...there used to be a signature here :)
03-26-2007 10:00 AM
Profile PM Web Find Quote Report
Volv
Skinning Contest Winner
*****

Avatar

Posts: 1233
Reputation: 31
34 / Male / Flag
Joined: Oct 2004
RE: Random Word [site]
code:
<?php
$words = array('word1', 'word2', 'word3'); //Fill an array with the random code words

$randomword = $words[rand(0, count($words)-1)]; //Pick a random code word from the array

echo $randomword; //Output the random code word to the page
?>


EDIT: Only noticed the EDIT in Eddie's above post just now, but I'll leave this post here in case anyone needs it for reference or something :p

This post was edited on 03-26-2007 at 12:14 PM by Volv.
03-26-2007 12:13 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On