Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: further discussion of zsh/random (was [PATCH] zsh/random module [UPDATED])



Having read all the criticism of the API, I still don't agree with the minimalist view nor do I favor implementing a mathfunc to mirror a semi-obscure API, and prefer to keep SRANDOM in a module that fails to load if no kernel random source is available  so I'm proposing a new API.

builtin:

zrandint -c count=1 -U upper=MAX_UINT32 -L lower=0 -s scalar -a array -f raw|hex|dec

    default output is equivalent to echo $SRANDOM. I can special case the nonsensical arguments like count=0 and upper=lower if that's the wish of the group. upper is inclusive

zrandbyte -c count=8 -s scalar -a array -f raw|hex|hex:|dec:

    default output format will be a colon-separated string of bytes encoded in hex, in an array hex and hex: are equivalent.  I could, instead, add another option to specify a separator and default to :.

Parameter:

SRANDOM

    A random, uniformly-distributed, unsigned, 32-bit integer.

mathfunc:

zrandomf()

    produces a random float-point number from 0 to 1  inclusive

zrandomi(upper=MAX_UINT32,lower=0,inclusive=0)

    takes 0 to 3 arguments.  exclusive by default to accommodate ${string[zrandomi($#string)+1]}

I'm not particularly tied to any of the names except SRANDOM





Messages sorted by: Reverse Date, Date, Thread, Author