Skip to main content

Timeline for Bash RANDOM with seed?

Current License: CC BY-SA 3.0

13 events
when toggle format what by license comment
Jan 12, 2022 at 20:01 comment added dash2 Might be useful to know whether the random seed will be reproducible across different machines, versions of bash, etc.
Dec 5, 2020 at 12:03 comment added Joachim Wagner It breaks if I add a pipe: bash -c 'RANDOM=42 ; for I in 1 2 3 ; do echo $RANDOM | md5sum ; done '
Nov 20, 2017 at 22:52 comment added G-Man Says 'Reinstate Monica' echo and RANDOM,   echo, bash and RANDOM,   echo, bash, SHELLOPTS and RANDOM,   RANDOM, bash, SHELLOPTS and RANDOM,   RANDOM, echo, RANDOM, RANDOM, bash and RANDOM,   RANDOM, RANDOM, RANDOM, echo and RANDOM,   RANDOM, RANDOM, RANDOM, RANDOM, RANDOM, RANDOM, baked beans, RANDOM, RANDOM, RANDOM and RANDOM, …    :-)   ⁠
Nov 20, 2017 at 15:44 comment added thrig @G-Man fear, surprise, interpolation, and a ruthless devotion to the Pope
Nov 18, 2017 at 0:58 comment added G-Man Says 'Reinstate Monica' Of course it should be bash -c 'RANDOM=42; echo "$RANDOM" "$RANDOM" "$RANDOM"'.
Nov 17, 2017 at 18:33 history edited thrig CC BY-SA 3.0
do not need export on SEED
Nov 17, 2017 at 18:26 history edited thrig CC BY-SA 3.0
elaborate on shell interpolation rules
Nov 17, 2017 at 17:56 comment added Philip Kirkbride @thrig I need double quotes because in my case it is actually random=$(bash -c "RANDOM=$mac; echo $RANDOM")
Nov 17, 2017 at 17:56 comment added Jeff Schaller Watch what happens if you do: set -x; FOO=42; bash -c "FOO=999; echo $FOO". The double-quotes are allowing the outer shell to replace $RANDOM with the outer shell's random; the inner bash shell is simply echoing an integer.
Nov 17, 2017 at 17:55 comment added thrig doublequotes is probably not what you want there
Nov 17, 2017 at 17:53 vote accept Philip Kirkbride
Nov 17, 2017 at 17:47 comment added Philip Kirkbride If I run random=$(bash -c "RANDOM=640; echo $RANDOM") shouldn't it return the same each time? Or is it because the $(bash ... isn't treated as a new instance of bash?
Nov 17, 2017 at 17:38 history answered thrig CC BY-SA 3.0