Skip to content

[OSH] Bash incompatibility: osh does not set/update $RANDOM #2569

@kseistrup

Description

@kseistrup

Oils 0.36.0 (commit 9440e2f)

[osh] ~$ printf '=%s=\n' "$RANDOM"
==
[osh] ~$ RANDOM=123
[osh] ~$ printf '=%s=%s=\n' "$RANDOM" "$RANDOM"
=123=123=

Bash 5.3.3

$ printf '=%s=\n' "$RANDOM"
=285=
$ RANDOM=123
$ printf '=%s=%s=\n' "$RANDOM" "$RANDOM"
=2850=18229=

bash(1) reads:

      RANDOM  Each time this parameter is referenced, it expands  to  a  random
              integer  between  0  and 32767.  Assigning a value to RANDOM ini‐
              tializes (seeds) the sequence of  random  numbers.   Seeding  the
              random number generator with the same constant value produces the
              same  sequence  of values.  If RANDOM is unset, it loses its spe‐
              cial properties, even if it is subsequently reset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions