Parcourir la source

Use non-deterministic rando by default.

scossu il y a 1 jour
Parent
commit
9e84300dc0
3 fichiers modifiés avec 27 ajouts et 9 suppressions
  1. 12 3
      README.md
  2. 14 2
      config/app.lua
  3. 1 4
      src/core.lua

+ 12 - 3
README.md

@@ -84,7 +84,7 @@ stage.
 
 ```
 # Note: tested on Archlinux. Other distros (especially Alpine) may need tweaks.
-eval $(luarocks path)  # for local install
+eval $(luarocks path)
 luarocks install --local debugger  # Not in dependencies file but temporarily required
 git clone --recurse-submodules https://git.knowledgetx.com/scossu/volksdata_lua.git
 cd volksdata_lua
@@ -94,7 +94,16 @@ cd ../
 git clone --recurse-submodules https://git.knowledgetx.com/scossu/pocket_archive.git
 cd pocket_archive
 luarocks build --local
-luarocks path >> ~/.bashrc  # or whatever shell init script you use at login
+# Add Luarocks paths to your login script
+luarocks path >> ~/.bashrc
+# Penlight.clonetree is not working properly. A pull request is in progress:
+# https://github.com/lunarmodules/Penlight/pull/496
+# In the meantime, clone the fork and install from the local repo:
+cd ../
+git clone https://github.com/scossu/Penlight.git
+cd Penlight
+luarocks build --local
+cd ../pocket_archive
 ```
 
 ### Run demo submission
@@ -126,7 +135,7 @@ If you don't have a configured web server yet, the provided `darkhttpd` will
 work in a pinch:
 
 ```
-cd ext/darkhttpd/
+cd ext/darkhttpd/  # Archlinux: sudo pacman -S darkhttpd
 make
 cd -
 ```

+ 14 - 2
config/app.lua

@@ -16,8 +16,20 @@ return {
     id = {
         -- Length in ASCII characters of system-generated IDs.
         len = 16,
-        -- Two seeds for the random ID generator.
-        seed = {256, 512},
+
+        --[[ Seed for the random ID generator.
+
+        Set this to an arbitrary integer in a test environment, so that
+        resource IDs will be generated with a consistent pattern for each run
+        (not when using pkar_watch, though). Note that each call to e.g.
+        `pkar deposit` will generate IDs starting from the same seed and will
+        overwrite resources from a previous deposit.
+
+        If nil, os.time() will be used, which generates always different random
+        IDs. This is necessary in a real-world application to avoid the above
+        mentioned overwriting.
+        ]]
+        seed = nil,
     },
     md = {
         -- Single-valued fields. TODO rely on content model cardinality.

+ 1 - 4
src/core.lua

@@ -115,10 +115,7 @@ setmetatable (M, mt)
 
 
 -- Initialize random ID generator.
--- TODO This must be set to completely random or use another random generator
--- so that resource IDs are not repeated for each process. For testing it's
--- convenient that resource IDs have always the same pattern.
-math.randomseed(M.config.id.seed[1], M.config.id.seed[2])
+math.randomseed(M.config.id.seed or os.time())
 
 
 return M