470,636 Members | 1,514 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

Random Condolance Generator

Hello,

I am the administrator for http://www.nickberg.org - Nick is the man
who was recently beheaded in Iraq.

He was a very ingenious man - once for my birthday had gave me a small
box wrapped in duck tape with a few diodes and two wires sticking out.

When attaching the wires to your skin the diodes would light up in a
random configuration. (he later modified this into a skin resistance
detector he dubed the "truth detector".)

I have been receiving hundreds of condolance letters, as you may well
imagine.

I would like to program a Random Condolance Generator that would pull
multiple random condolances from a database (with the html script
already included) - but not the same condolance twice within several
clicks of the submit button.

Can you direct me to someone or somewhere that we could get started on
this program?

Thank you very much,
Luke
Jul 23 '05 #1
5 2931
Luke wrote:
Hello,
I would like to program a Random Condolance Generator that would pull
multiple random condolances from a database (with the html script
already included) - but not the same condolance twice within several
clicks of the submit button.

Can you direct me to someone or somewhere that we could get started on
this program?
Not from a database, but:

function getRandomSelectionFromArray(array){
return array[new Date()%array.length]
}

condolences = ["Sex","Drugs","Rock and roll.","Decline of Western
civilization."]

This doesn't avoid duplicates, you'd need to this server-side(or a
combination of ss and client-side).
Mick
Thank you very much,
Luke

Jul 23 '05 #2
st*****@nickberg.org (Luke) wrote in message news:<b2**************************@posting.google. com>...
Hello,

I am the administrator for http://www.nickberg.org - Nick is the man
who was recently beheaded in Iraq....
I have been receiving hundreds of condolance letters, as you may well imagine.


I would like to program a Random Condolance Generator (nick would like it)
that would pull multiple random condolances from a database (with the html
script already included) - but not the same condolance twice within several
clicks of the submit button.

Can you direct me to someone or somewhere that we could get started on
this program?

Thank you very much,
Luke

Btw, the condolences generated (in thread sp error) must come from
another file, either excel or text, w/o loading the entire file into
the webpage...
Text is currently stored in excell as such:
row 1:
<div align=center><p><font face=verdana size="-1"> sentence to
paragraph of text <P> <br><font color=#3f5278> Person's Name
</font><BR> Person's Location (sometimes blank) </div>
<hr width="26%" hight=2>

row 2:
<div align=center><p><font face=verdana size="-1"> sentence to
paragraph of text <P> Person's Name <br><font color=#3f5278>
</font><BR> Person's Location (sometimes blank) </div>
<hr width="26%" hight=2>

row 3: etc...
I can easily add a row to have increasing numerals for referencing...
The most important aspects are - coming up with five unique random
numbers
(that do not repeat for at least a couple reloads, if possible)
- extricating the html line from the database w/o loading the whole
thing

Suggestions? - Those who help will be credited in perpetuity
somewhere in http://nickberg.org, ( or at least as long as I'm the
administrator)

Thanks, Luke
Jul 23 '05 #3
"Luke" <st*****@nickberg.org> wrote
st*****@nickberg.org (Luke) wrote
I am the administrator for http://www.nickberg.org - Nick is the man
who was recently beheaded in Iraq....
I have been receiving hundreds of condolance letters, as you may
well imagine.
I would like to program a Random Condolance Generator (nick would like
it) that would pull multiple random condolances from a database (with
the html script
HTML is not script.
already included) - but not the same condolance twice within
several clicks of the submit button.
Can you direct me to someone or somewhere that we could get started on
this program?


http://www.project-euh.com/

<META NAME="description"
CONTENT="Project Euh? WARNING: random pages, please get lost!">

has a similar idea. They use cookies. And every click directs to a page
called /random.html which reads that cookie, and redirects accordingly.
Btw, the condolences generated (in thread sp error) must come from
another file, either excel or text, w/o loading the entire file into
the webpage...
You have some serverside scripting to do then. Do you have PHP, ASP or
anything? Javascript can, in some browsers, make http requests. That is: it
can request a file. The server needs to be able to extract the appropriate
random line and deliver it as a individual file.
See <URL: http://jibbering.com/2002/4/httprequest.html >
But you 'll be amazed how fast it can come up with 100 lines. If speed is
the only concern, it would be less demanding to get several entries
together.

Or dive into Java (a far cousin of JavaScript) and build an applet. They can
do more (and less).
Text is currently stored in excell as such:
row 1:
<div align=center><p><font face=verdana size="-1"> sentence to
paragraph of text <P> <br><font color=#3f5278> Person's Name
</font><BR> Person's Location (sometimes blank) </div>
<hr width="26%" hight=2>

row 2:
<div align=center><p><font face=verdana size="-1"> sentence to
paragraph of text <P> Person's Name <br><font color=#3f5278>
</font><BR> Person's Location (sometimes blank) </div>
<hr width="26%" hight=2>

row 3: etc...

Just fine. Just as long as the server can turn it into something javascript
can read. Each row is a string, although a pretty nasty one, with single and
double quotes all around. To add this to the document, you can use innerHTML
directly, or break the string up with regular expressions to find out the
structure of elements to add using the DOM (document object model).

This innerHTML thing is not part of the official standard, but is available
in most browsers in use today. It can be as simple as this:
//---------------
document.body.innerHTML += row3;
//---------------

Although "most browsers" is an understatement, going the official way of the
DOM has a few advantages. And using classes rather than font tags you can
easily make it look alright. Advanced css floats and margins allow control
of everything.

Suppose the server returned a string like
//---------------
var returnedstring = "paragraph of text|Person's Name|";
var pieces=returnedstring.split('|');
//---------------

Variable pieces is now an array of length three, the last element happens to
be empty. We can build a structure of elements using the DOM and fill them
with these texts:
//---------------
var div=document.createElement('div'); // or TR
div.className='condolance';
var p=document.createElement('p'); // or TD

var x=p.cloneNode(false); // faster than createElement twice
x.className='thetext';
x.appendChild(document.createTextNode(pieces[0]));
div.appendChild(x);

x=p.cloneNode(false);
x.className='personsname';
x.appendChild(document.createTextNode(pieces[1]));
div.appendChild(x);

if( parts[2] ){
var x=p.cloneNode(false);
x.className='personslocation';
x.appendChild(document.createTextNode(pieces[2]));
div.appendChild(x);
}

document.body.appendChild( div ); // or append to table tbody
//---------------
This gets repetitve. Depending your ideas something more efficient may be
written.
I can easily add a row to have increasing numerals for referencing...

The most important aspects are - coming up with five unique random
numbers
(that do not repeat for at least a couple reloads, if possible)
Again it depends on how you find and store your information, the number of
total, etc. The following script creates an array of five numbers, each of
them garanteed unique.
//---------------
function rand(){return Math.floor(Math.random()*10);}

var ar=new Array();
for( var i=0; i<5; i++ ){
var x=rand();
for( var j=i; j--; ){ if(ar[j]==x){ i--; break; } }
ar[i]=x;
}
alert(ar);
//---------------

- extricating the html line from the database w/o loading the whole
thing
Serverside or Java. See above, this cannot be done by Javascript.
Suggestions? - Those who help will be credited in perpetuity
somewhere in http://nickberg.org, ( or at least as long as I'm the
administrator)

Thanks, Luke


BTW, bridge the world

Jul 23 '05 #4
On Sun, 23 May 2004 05:55:40 +0200, Abel wrote:
You have some serverside scripting to do then. Do you have PHP, ASP or
anything? <snip>

..jsp as well. (Java on the server-side)

I notice the site is coming off Win2K/IIS 5.0
<http://uptime.netcraft.com/up/graph/?host=nickberg.org>
Sounds like .asp might be the best bet.
Or dive into Java (a far cousin of JavaScript) and build an applet. They can
do more (and less).


I think an applet is not the best
choice for this, you can do it
pretty much all on the server side,
if the server supports scripting.

Even if you had to rely on some client-side
JS call, it would probably be both quicker,
and compatible with a wider range of
browsers, than an applet.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #5
Ivo
"Abel" <go*@help.us> wrote
"Luke" <st*****@nickberg.org> wrote
st*****@nickberg.org (Luke) wrote
I am the administrator for http://www.nickberg.org - Nick is the man
who was recently beheaded in Iraq....
> I have been receiving hundreds of condolance letters, as you may
> well imagine.

I would like to program a Random Condolance Generator (nick would like
it) that would pull multiple random condolances from a database (with
the html script
HTML is not script.
already included) - but not the same condolance twice within
several clicks of the submit button.
Can you direct me to someone or somewhere that we could get started on
this program?

If you validate your page at
<URL: http://validator.w3.org/check?uri=ht.../nickberg.org/ >
you 'll find the beginning of a long journey towards proper markup. Then if
you put every message in its own <div> tag with style="display:none", all
you need is Abel's unique randomizer to decide which one to turn visible
next. An optimum would perhaps be to download 50-100K per request. If that
does not give you enough condolances, I don't think a hundredfold would.
it depends on how you find and store your information, the number of
total, etc. The following script creates an array of five numbers, each of
them garanteed unique.
//---------------
function rand(){return Math.floor(Math.random()*10);}

var ar=new Array();
for( var i=0; i<5; i++ ){
var x=rand();
for( var j=i; j--; ){ if(ar[j]==x){ i--; break; } }
ar[i]=x;
}
alert(ar);
//---------------


HTH
Ivo
Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Brandon Michael Moore | last post: by
28 posts views Thread by Paul Rubin | last post: by
3 posts views Thread by Joe | last post: by
70 posts views Thread by Ben Pfaff | last post: by
5 posts views Thread by Peteroid | last post: by
104 posts views Thread by fieldfallow | last post: by
13 posts views Thread by porterboy76 | last post: by
2 posts views Thread by Matthew Wilson | last post: by
3 posts views Thread by Daniel | last post: by
1 post views Thread by Korara | last post: by
???
reply views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.