top | item 40843104

(no title)

jzwinck | 1 year ago

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.

discuss

order

eternityforest|1 year ago

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.

paulmd|1 year ago

hey mods hire this one

paulmd|1 year ago

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)?

Mo3|1 year ago

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