zsh-workers
 help / color / mirror / code / Atom feed
From: Clinton Bunch <cdb_zsh@zentaur.org>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] zsh/random module [UPDATED]
Date: Tue, 22 Nov 2022 13:48:33 -0600	[thread overview]
Message-ID: <044fe1d3-e353-3830-f2cc-2c0580892dc2@zentaur.org> (raw)
In-Reply-To: <58053-1669139059.235596@kmQr.TTfz.Qbdo>

I

On 11/22/2022 11:44 AM, Oliver Kiddle wrote:
> Firstly, thanks for your work on this Clinton and for being patient with us.
>
> Bart Schaefer wrote:
>> Actually this could be done with -ap for SRANDOM and -af for zrandom,
>> as well, but they're much simpler and the only reasonable quibble
>> might be with the name "zrandom".
> Bash appears to have an SRANDOM and if this is compatible with that then
> I'd see no issue with having that feature autoload the module.
>
> The builtin's option letter API looks good to me.

based on feedback, more and more I'm thinking the default action, 
instead of returning a hex-string of 8 bytes should return the 
equivalent of echo $SRANDOM. -c would always default to 1 even when 
using -r, and -i would be removed and become the default functionality 
as saving an array of decimal byte values could be achieved with -U 255 
and -c.


>
> If we're going to quibble about naming, many of our modules use 'z'
> prefixes on their builtins so I'd favour zrandom for the builtin too.
> The use of "get" and "set" in naming is often superfluous and "get"
> implies the fetching of something that already exists rather than
> of something that needs to be created.
I thought it would be confusing to have both named zrandom, but I'm not 
opposed to the idea.
> What issue do you see with "zrandom" on the math function? Most of the
> existing math functions correspond fairly closely to libc counterparts.
> Distinguishing it from those seems reasonable.
>
> The question of why $RANDOM isn't backed by some secure modern and fancy
> implementation seems to come up roughly yearly. It's not a feature I use
> especially often and I certainly don't care, either about stability or
> security, on the rare occasion I use *(oe:REPLY=\$RANDOM:) to shuffle
> a few mp3 files when playing them. Neither would I have any special
> attachment to the existing $RANDOM implementation if it was changed in a
> compatible way.
>
> Given that it can be autoloaded, could we move $RANDOM to the module
> too?

I suppose we could move RANDOM and use rand_r to try to keep the 
documented behavior, though currently the behavior is not consistent.

I tried changing the other places zsh uses rand to use rand_r and found 
that on at least EL8 the use of rand48 screwed up the sequence even when 
using rand_r for RANDOM.  I'm guessing glibc uses the same engine for 
rand_r and erand48 and doesn't reset the upper 16 bits when rand_r is 
called after erand48, but I haven't dug into the code.

I'd rather make RANDOM a 15-bit integer sampled from the same source as 
SRANDOM, but it would mean completely breaking an only partially broken 
documented behavior.

>
> Oliver
>


  reply	other threads:[~2022-11-22 19:48 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02 17:13 [PATCH] zsh/random module Clinton Bunch
2022-11-03 17:50 ` Bart Schaefer
2022-11-04  3:17 ` dana
2022-11-04  6:22   ` Clinton Bunch
2022-11-04  7:27     ` dana
2022-11-04 12:57       ` Clinton Bunch
2022-11-08  0:18         ` [PATCH] zsh/random module [UPDATED] Clinton Bunch
2022-11-18 14:30           ` Clinton Bunch
2022-11-19  6:42             ` Lawrence Velázquez
2022-11-18 16:23           ` Stephane Chazelas
2022-11-18 17:08             ` Clinton Bunch
2022-11-18 18:12               ` Stephane Chazelas
2022-11-18 18:38                 ` Clinton Bunch
2022-11-23 19:52                   ` Daniel Shahaf
2022-11-24 16:19                     ` Stephane Chazelas
2022-11-24 16:30                       ` Roman Perepelitsa
2022-11-24 22:39                         ` Clinton Bunch
2022-11-25  8:53                           ` Stephane Chazelas
2022-11-25  9:40                             ` Stephane Chazelas
2022-11-28 16:37                               ` further discussion of zsh/random (was [PATCH] zsh/random module [UPDATED]) Clinton Bunch
2022-11-21  1:07           ` [PATCH] zsh/random module [UPDATED] Matthew Martin
2022-11-21  1:59             ` Clinton Bunch
2022-11-21  2:21               ` Matthew Martin
2022-11-21  2:57                 ` Clinton Bunch
2022-11-21  3:14                   ` Lawrence Velázquez
2022-11-21  4:17                     ` Bart Schaefer
2022-11-21  5:05                       ` Clinton Bunch
2022-11-22 13:42                         ` dana
2022-11-23 19:49                         ` Daniel Shahaf
2022-11-22 17:44                       ` Oliver Kiddle
2022-11-22 19:48                         ` Clinton Bunch [this message]
2022-11-23  1:23                   ` Matthew Martin
2022-11-23  2:58                     ` Clinton Bunch
2022-11-23  4:14                       ` Matthew Martin
2022-11-23 13:41                         ` Clinton Bunch
2022-11-23 20:33                           ` Daniel Shahaf
2022-11-23 21:42                             ` dana
2022-11-23 23:54                               ` Daniel Shahaf
2022-11-24  0:17                                 ` Daniel Shahaf
2022-11-24  1:05                                 ` dana
2022-11-24 13:52                               ` Clinton Bunch
2022-11-23 19:46           ` Daniel Shahaf
2022-11-24  2:58             ` Clinton Bunch
2022-11-24 10:07               ` nimaje+zml
2022-11-24 13:19                 ` Clinton Bunch
2022-11-24 14:33             ` Clinton Bunch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=044fe1d3-e353-3830-f2cc-2c0580892dc2@zentaur.org \
    --to=cdb_zsh@zentaur.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).