Random word on a web page every 1/10 of a second

I am developing a small web development application (javascript) for an art project. This is called a "Poetry Generator", and it is a script that generates random verses based on user input.

The script should display a random word to the user every 1/10 of a second. The word list used is 109.582 words.

I have already tried different solutions:

  • put all the words in a text file and get a random line of the text file → too slow (and the user needs to download a 3 MB text file before you can use the application).
  • put all the words in an array in javascript. → javascript arrays apparently can't handle 109.585 elements
  • pull words from a database using the jQuery Ajax function using the Javascript interval function -> this solution worked fine when testing on my local host, but after loading into a real web environment this method turned out to be too slow. (And I could imagine that my hosting provider would not be so happy if every time I made 10 requests to my server.)

So ... Does anyone know of a different approach that I could use to display a random word on a web page every 1/10 of a second? It does not have to use php or javascript, if it works in browsers, I am happy!

Thanks in advance

Teis

+3
source share
3 answers

, . ( 600 ), javascript .

, , 600.

, , , ! memcached , , .

+4

JS. , 1000 () .

+4

Until you need to generate an insanely long text, you coldly divide randomization into two stages:

First, pre-select some server-side words (say 5000?)

Then , on the client side, use JS to select even more randomly from the selected words.

Pros: additional requests are not required; JS must process the array, large

+3
source

All Articles