
Ask HN: How do you think this site works? - aerovistae
For those who haven&#x27;t read the short story <i>The Library of Babel</i> by Borges, it&#x27;s about a fictional universe consisting of an infinite library filled by books which contain every possible combination of letters from the English alphabet.<p>In the story, people wander the vast Library for all their lives, seeking books which hold anything recognizable. Statistically, the odds of finding a book with even one intelligible sentence is next to nothing. But in theory, if every story is written there, then somewhere is a book which predicts your whole life, and another which tells correctly the location of any book you might seek, and so on.<p>This website reproduces that fictional universe in digital form. But if you look at the About page, it explicitly says that they do <i>not</i> simply generate and store each page as it&#x27;s requested.<p>So how could this work? Click &quot;Browse&quot; to enter the library, or &quot;Search&quot; to find any text you can imagine somewhere in the library. The &quot;Search&quot; function confounds me more than any other aspect of this. Try a lengthy sentence describing you, even use your own name, and it&#x27;s there, of course.....but how can it find it so fast?<p>https:&#x2F;&#x2F;libraryofbabel.info&#x2F;
======
Someone
_" it explicitly says that they do not simply generate and store each page as
it's requested."_

Firstly, they might be lying. Secondly, they more likely are not "generating
and storing it" because they are generating it, but not storing it. If you
want repeatability (but why would you? In an infinite library, you cannot
expect to find the same text twice), use the text entered as the seed for a
RNG, use it to pick the #of characters to prepend and to append, then generate
the two sequences. That gives you repeatability without the need for a backing
store.

A way to test this theory is by entering a long string first, and then a
substring of it, say with the last character removed. If they stored the first
result, they could return it for the second search, too. I haven't seen that
happen.

Also, repeatedly searching for the same text gave me texts where the search
text appears in the same location. So, apparently, they partly implemented the
repeatable generation process.

------
HoopleHead
On mobile at the moment, so can't examine the source. But I suspect it's just
injecting your search term into a page of randomly generated characters

