3 ms·
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 num
by jzwinck 2y 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.
- Mo3 2y agoAnd how would you invalidate the generated codes after 5 days? And is this even scalable to more than one Postzegelcode in circulation?
- paulmd 2y agothat 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)?
- eternityforest 2y agoWhy 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 2y agohey mods hire this one