zsh-workers
 help / color / mirror / code / Atom feed
From: Clinton Bunch <cdb_zsh@zentaur.org>
To: zsh-workers@zsh.org
Subject: Re: preliminary patch for zsh/random module
Date: Mon, 24 Oct 2022 16:15:24 -0500	[thread overview]
Message-ID: <4d288abe-5f72-6cff-9704-e80ae4b4e07b@zentaur.org> (raw)
In-Reply-To: <08cb4c65-acd4-ba91-d82d-b8f3943aed8b@zentaur.org>

[-- Attachment #1: Type: text/plain, Size: 2567 bytes --]


On 10/24/2022 8:20 AM, Clinton Bunch wrote:
> On 10/23/2022 11:47 PM, Bart Schaefer wrote:
>> On Sun, Oct 23, 2022 at 7:57 PM Clinton Bunch <cdb_zsh@zentaur.org> 
>> wrote:
>>> On 10/23/2022 9:01 PM, Bart Schaefer wrote:
>>>> * Typo in the introductory comment.
>>> I'm pretty sure I've since found and changed all the instances of
>>> Zoltan's name.
>> I was referring to the spelling of "randome".
>>
>>>> Actual question:  What's the use case for returning or printing a
>>>> block of random bytes?  Why does this need to be a builtin?
>>> Mostly because I see constructs like read -k6 -u3 3</dev/urandom
>> ... because?
>
> I did it to seed rand48.  Roman did it to generate a 32-bit random 
> integer.  Both of which are obsoleted by other parts of this module.
>
> I'm sure there are other reasons someone might want to read more or 
> less than 4 bytes of random data.  One that comes to mind is 
> generating a password in a platform-independent way without assuming 
> perl or python.
>
Here's an example:

randpw () {
         local 
chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890@#%&()"
         local tmp
         local -i num
         num=${1:-10}
         getrandom -l $num -s tmp
         for i in {1..${#tmp}..2}
         do
                 print -n ${chars["16#${tmp[$i,$i+1]}"%${#chars}+1]}
         done
         echo
}

>>
>>> it would be nice to initialize an array with random numbers without
>>> having to use a loop to access SRANDOM n times.
>> But you're not filling an array with random numbers, you're filling a
>> string (scalar) with random bytes.
> Actually, it does both.
>>
>>>> Suggestion:  Treat SRANDOM like SECONDS, in that you can change the
>>>> type from integer to floating-point.  Then maybe the zrandom() math
>>>> function isn't needed?
>>> That would seem confusing to me, and too easy to forget which state you
>>> left it in.
>> You make it local so you're not leaving it.
>>
>> () {
>>   print $SECONDS;
>>   () {
>>    local -F SECONDS
>>    print $SECONDS
>>   }
>>   print $SECONDS
>> }
>> 56
>> 0.0000050000
>> 56
> Still seems like something you do because you can rather than because 
> it's intuitive to the user.  Also, your example assumes you'd only 
> want to do this in a function (or wrap it in an anonymous function 
> just for this purpose)
>>
>>> zrandom was meant to be a replacement for rand48
>> OK.
>>
>
>

[-- Attachment #2: Type: text/html, Size: 4928 bytes --]

      reply	other threads:[~2022-10-24 21:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-23  3:43 Clinton Bunch
2022-10-24  2:01 ` Bart Schaefer
2022-10-24  2:56   ` Clinton Bunch
2022-10-24  4:47     ` Bart Schaefer
2022-10-24 13:20       ` Clinton Bunch
2022-10-24 21:15         ` Clinton Bunch [this message]

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=4d288abe-5f72-6cff-9704-e80ae4b4e07b@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).