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

Re: [PATCH] zsh/random module [UPDATED]



2022-11-23 19:52:22 +0000, Daniel Shahaf:
[...]
> > > Alternatively, you could add a -f %02x, -f %u -f %c and do
> > > without the -r/-i, with default -c 8 -f %02x -L 0 -U 255.
> > That seems a lot more confusing than -r (raw) or -i (integer) unless it's
> > expanded to a lot more arbitrary formats.  At least for someone not familiar
> > with printf formats.
> 
> Could have something like this:
> 
>     "-f:specify format:(raw hex decimal)"
> 
> It's extensible and readable.  (Could easily extend it to support printf
> formats, or uppercase/lowercase hex variations, etc..)  Also, it uses
> one fewer short option :)

You'd then need a separate option for length/padding/truncating
of those numbers and maybe even an endianness one.

For instance, without -i, at the moment, you get 0-padding of
the numbers to length 2. I'd expect with -i -f hex, you'd want
either 0xabcde or 000ABCDE. With -f raw -L -12 -U 1234, you'd
want to specify if it's short/int/long you want dumped, etc.

To me, having $SRANDOM added to core zsh, and maybe a
randint(first, last) added to zsh/math would be more than
enough.

To get a stream of random bytes, /dev/urandom is best.
and we have read/sysread to get that.

We have printf / print -f for formatting numbers already.

As already said, having some equivalent of perl's pack/unpack to
interpret/generate binary data would be more useful than adding
that functionality to every new builtin that deals with some
form of binary data.

-- 
Stephane




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