Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You don't need a full scan or a giant CSV file. You can do it with a single small file in a single directory. The file contains the state of a pseudo random number generator. On each request, generate a number, save the new PRNG state into a new temp file in a subdirectory, and rename the temp file over top of the original file. If renaming fails, try the whole process a few more times. This allows multiple processes to serve requests concurrently.

Exercise for the reader: avoid re-reading the PRNG state file on retries.



Why would you do all that when there's databases engines?

I don't quite understand why programmers love minimalism more than reusing widely trusted and very easy solutions that are known to perform well.


hey mods hire this one


that sounds like a badly home-rolled uuid4 with extra steps.

How about instead we just generate a uuid4, insert it into a sqlite file or Postgres database, and then the postzegelcode value is threefry(SECRET,uuid)?


And how would you invalidate the generated codes after 5 days? And is this even scalable to more than one Postzegelcode in circulation?




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

Search: