Selecting a "random" quotation



Here is some code I use to select a "random" quotation to put an a web
page. It changes every 4 hours.

/**
* 86,400,000 the number of milliseconds in 24 hour day. Easily
fits into an int.
* We change the quotations every 4 hours, UTC.
*/
private static final int CHANGE_INTERVAL_IN_MILLIS = 4 * 60 * 60 *
1000;



final Adler32 digester = new Adler32();
int seed = ( int ) ( System.currentTimeMillis() /
CHANGE_INTERVAL_IN_MILLIS );
/// digester.update(int) not clearly documented, probably
wants ubyte.
digester.update( ( byte ) ( seed & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 8 ) & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 16 ) & 0xff ) );
digester.update( ( byte ) ( ( seed >>> 24 ) & 0xff ) );
digester.update( fileBeingProcessed.getPath().getBytes(
"UTF-8" ) );

// get rid of high sign bit, and low bit, which seem to be
1 disproportionately.
final int digest = (( ( int ) digester.getValue() ) << 1)
2;
final String[] candidates = category.getQuotations();

final String chosenQuote = candidates[ digest %
candidates.length ];

However it often SEEMS to sometimes pick the same quote for two
different pages, more often than I would intutitively think it would.

Further it SEEMS to favour certain quotes in the collection. I wonder
if this just my imagination, or there is some flaw in the algorithm.

--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.



Relevant Pages

  • Re: gekko commits libel
    ... This is an attribution line. In this, ... content is a quotation and it's been attributed, ... very good medium for counting on indentation to appear as ... You add another double quote at the front ...
    (misc.writing)
  • Re: Position of period
    ... You can find at least one authoritative British reference ... portion predominates, the period should precede the quote. ... When the quotation is long, or made up of more than ...
    (alt.usage.english)
  • Re: More on the geocentrism issue
    ... >> "To assert that the earth revolves around the sun is as erroneous as to ... > quotation has given an original source. ... > as to claim that Jesus was not born of a virgin. ... the first line of that quote sounds exactly like the quote ...
    (talk.origins)
  • Re: Misquotations [WAS: He knelt him at that word.]
    ... whether the speaker was *trying* to quote a source known to him. ... criterion--the phrase almost but not quite matches the quotation. ... "I don't like chocolate chocolate-chip cookies." ...
    (alt.usage.english)
  • Re: More on the geocentrism issue
    ... >>> quotation of Bellarmine. ... the first line of that quote sounds exactly like the quote ... > the sun really is fixed in the center of the heavens and only revolves ... >> Scripture and sound theology, ...
    (talk.origins)