zsh-workers
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: "Daniel Shahaf" <d.s@daniel.shahaf.name>,
	"Clinton Bunch" <cdb_zsh@zentaur.org>
Cc: "Zsh hackers list" <zsh-workers@zsh.org>
Subject: Re: [PATCH] zsh/random module [UPDATED]
Date: Wed, 23 Nov 2022 15:42:06 -0600	[thread overview]
Message-ID: <869f6d65-15d2-477f-b78b-02427a0c1395@app.fastmail.com> (raw)
In-Reply-To: <20221123203329.GP27622@tarpaulin.shahaf.local2>

On Mon 7 Nov 2022, at 18:18, Clinton Bunch wrote:
> '(-r)-L+[specify integer lower bound (implies -i)]: :_numbers -d$lmin -l$lmin -m$max "integer lower bound"' \
> '(-r)-U+[specify integer upper bound (implies -i)]: :_numbers -d$umax -l$umin -m$max "integer upper bound"'

Was going to mention in my draft reply that the $max references here are
broken now

On Wed 23 Nov 2022, at 13:46, Daniel Shahaf wrote:
>   + Why should -c default to 8 in the "random bytes" case?  Why
>     shouldn't it default to some other value, or even be required to be
>     specified explicitly by the user? ...
> - Why should -c's default depend on anything at all?  You mentioned
>   downthread you consider making -c1 the default in all cases; that'd be
>   better.

The defaults with this API are kind of weird, because if you make them
dependent on the format (e.g. 8 for hex and 1 for everything else) it's kind
of arbitrary, but if you keep them all the same (e.g. 1 or 8 for everything)
they aren't generally useful — i think it's safe to assume that 'i would like
exactly 1 random hex digit' is not going to be the most common use case

Requiring the user to explicitly specify it would address that, though you
could say then that it goes the other way, e.g. again it's probably safe to
assume that 90% of the time you're only going to want one integer value, and
making people write that out every time, whilst expected in a lower-level API
like a C function, is maybe annoying in a convenience shell built-in

But annoying is probably better than confusing, if those are the options

On Wed 23 Nov 2022, at 13:46, Daniel Shahaf wrote:
>> +%test
>> +  getrandom -U 56
>> +1f:Checking if system has a kernel random source
>> +?(eval):1: No kernel random pool found.
>> +
>
> The test point's code has nothing to do with the test point's
> description and expected errput.

The assertion is backwards but i guess this is just testing to see if the
module works on the system. But should that even be a test? Shouldn't there
instead be a %prep that just leaves the whole file unimplemented in this case?
Unless we're expecting the module to be both available and usable on every zsh
build

On Wed 23 Nov 2022, at 13:46, Daniel Shahaf wrote:
> Oh, and bump that 16 to something 3 or 4 times as big, because a 1/65536
> chance isn't really enough in a world where automated builds (CI,
> distros' QA, etc.) is a thing.

I feel like it should be very nearly impossible for a test to fail just for
randomness reasons. Maybe it's over-kill but in my draft reply to the patch i
was going to suggest something like this:

  () {
    repeat $(( 10 ** 5 )); do
      getrandom -L4 -U5 -c64 -a tmpa
      [[ $tmpa[(r)5] == 5 ]] && return 0
    done
    return 1
  }

On Wed 23 Nov 2022, at 13:52, Daniel Shahaf wrote:
> Could have something like this:
>
>     "-f:specify format:(raw hex decimal)"

I kind of like that

On Wed 23 Nov 2022, at 14:33, Daniel Shahaf wrote:
> 4. Which approach generalizes better?

If we were to directly expose an underlying C API as in Matthew's proposed
arc4random_uniform(), i think it would make sense to remain consistent with
that API. But in any other case i would prefer inclusive, and i think that
fits nicely with other things in zsh as you said

dana


  reply	other threads:[~2022-11-23 21:44 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
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 [this message]
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=869f6d65-15d2-477f-b78b-02427a0c1395@app.fastmail.com \
    --to=dana@dana.is \
    --cc=cdb_zsh@zentaur.org \
    --cc=d.s@daniel.shahaf.name \
    --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).