Random Condolance Generator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luke

    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
  • Mick White

    #2
    Re: Random Condolance Generator

    Luke wrote:
    [color=blue]
    > Hello,
    >[/color]
    [color=blue]
    > 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?[/color]

    Not from a database, but:

    function getRandomSelect ionFromArray(ar ray){
    return array[new Date()%array.le ngth]
    }

    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[color=blue]
    >
    > Thank you very much,
    > Luke[/color]

    Comment

    • Luke

      #3
      Re: Random Condolance Generator

      stories@nickber g.org (Luke) wrote in message news:<b20c34de. 0405211942.2226 8a21@posting.go ogle.com>...[color=blue]
      > Hello,
      >
      > I am the administrator for http://www.nickberg.org - Nick is the man
      > who was recently beheaded in Iraq....[color=green]
      >> I have been receiving hundreds of condolance letters, as you may[/color][/color]
      well[color=blue][color=green]
      >> imagine.[/color]
      >
      > 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[/color]


      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

      Comment

      • Abel

        #4
        Re: Random Condolance Generator

        "Luke" <stories@nickbe rg.org> wrote[color=blue]
        > stories@nickber g.org (Luke) wrote[color=green]
        > > I am the administrator for http://www.nickberg.org - Nick is the man
        > > who was recently beheaded in Iraq....[color=darkred]
        > >> I have been receiving hundreds of condolance letters, as you may
        > >> well imagine.[/color]
        > >
        > > 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[/color][/color]

        HTML is not script.
        [color=blue][color=green]
        > > 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?[/color][/color]

        Project Euh? WARNING: random pages, please get lost!


        <META NAME="descripti on"
        CONTENT="Projec t 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.
        [color=blue]
        > 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...[/color]

        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).
        [color=blue]
        > 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...
        >[/color]

        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.i nnerHTML += 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=returned string.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.cr eateElement('di v'); // or TR
        div.className=' condolance';
        var p=document.crea teElement('p'); // or TD

        var x=p.cloneNode(f alse); // faster than createElement twice
        x.className='th etext';
        x.appendChild(d ocument.createT extNode(pieces[0]));
        div.appendChild (x);

        x=p.cloneNode(f alse);
        x.className='pe rsonsname';
        x.appendChild(d ocument.createT extNode(pieces[1]));
        div.appendChild (x);

        if( parts[2] ){
        var x=p.cloneNode(f alse);
        x.className='pe rsonslocation';
        x.appendChild(d ocument.createT extNode(pieces[2]));
        div.appendChild (x);
        }

        document.body.a ppendChild( div ); // or append to table tbody
        //---------------
        This gets repetitve. Depending your ideas something more efficient may be
        written.
        [color=blue]
        > 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)[/color]

        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);
        //---------------

        [color=blue]
        > - extricating the html line from the database w/o loading the whole
        > thing[/color]

        Serverside or Java. See above, this cannot be done by Javascript.
        [color=blue]
        > 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[/color]

        BTW, bridge the world



        Comment

        • Andrew Thompson

          #5
          Re: Random Condolance Generator

          On Sun, 23 May 2004 05:55:40 +0200, Abel wrote:
          [color=blue]
          > You have some serverside scripting to do then. Do you have PHP, ASP or
          > anything?[/color]
          <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.
          [color=blue]
          > Or dive into Java (a far cousin of JavaScript) and build an applet. They can
          > do more (and less).[/color]

          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

          Comment

          • Ivo

            #6
            Re: Random Condolance Generator

            "Abel" <god@help.us> wrote[color=blue]
            > "Luke" <stories@nickbe rg.org> wrote[color=green]
            > > stories@nickber g.org (Luke) wrote[color=darkred]
            > > > 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[/color][/color]
            >
            > HTML is not script.
            >[color=green][color=darkred]
            > > > 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?[/color][/color][/color]

            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.
            [color=blue]
            > 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);
            > //---------------[/color]

            HTH
            Ivo


            Comment

            Working...