Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: How do you think this site works?
1 point by windowshopping on April 29, 2016 | hide | past | favorite | 2 comments
For those who haven't read the short story The Library of Babel by Borges, it's about a fictional universe consisting of an infinite library filled by books which contain every possible combination of letters from the English alphabet.

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.

This website reproduces that fictional universe in digital form. But if you look at the About page, it explicitly says that they do not simply generate and store each page as it's requested.

So how could this work? Click "Browse" to enter the library, or "Search" to find any text you can imagine somewhere in the library. The "Search" function confounds me more than any other aspect of this. Try a lengthy sentence describing you, even use your own name, and it's there, of course.....but how can it find it so fast?

https://libraryofbabel.info/




"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.


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




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: