Description
expected behaviour of std / random is that the following should output always the same result, which it does not unless I remove nimib import:
import std / random
import nimib # if I comment this lines results are reproducible
echo rand(100)
this is a side effect of the dependency on tempfile, see: OpenSystemsLab/tempfile.nim#13
this is particular bad in nimib since tempfile is called every time a new nbCode is created (a temporary file is created to save the output) and this seems to trigger a new call to randomize. This means that a single randomize(42)
call after importing nimib is not enough to guarantee reproducible results, the user must call randomize with a fixed seed inside every code block that calls random functions.
import nimib
import std / random
randomize(42) # putting a randomize here does not guarantee reproducible results
nbInit
nbCode:
randomize(42) # putting randomize here does!
echo rand(100)
echo nb.blk.output
An alternative to tempfile are some utilities in std lib but they do not yet support the same functionalities of tempfile: https://nim-lang.org/docs/tempfiles.html