From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HTML_MESSAGE,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 11877 invoked from network); 24 Oct 2022 21:16:04 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Oct 2022 21:16:04 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1666646164; b=VuEYIq7kGYggsDguTXyQ0du2p1D4DyU1zt6LxKynSXpgs6dsh17UsvmrqzJYsgCRVX+MSRHGqO igWQfgGUk47kjv9Hkb063PTLIbcc33+XfhQn5CimgIR/H8AAXUMXdSGCCmefNBoL1ephC1vnnN XDpfJt7v8nE7fQ21z7tRrnYPlM2RNytDRv8lBZAmli4gImat8z+ZBS+OHC4bG+6B5qVv255JKL 1RZhzBadT+zWKsr0jynum2jnh8qjdT4aq02COVUMUSA0PnGJpj/tN7z36cvx5r21PaA+8ueqzg pHYTxhJ2cpnAG/IfH+9G80np/jLqptA8TYL4aL5YlIwsDw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (iris.zentaur.org) smtp.remote-ip=198.58.127.206; dkim=pass header.d=zentaur.org header.s=dkim20200120 header.a=rsa-sha256; dmarc=pass header.from=zentaur.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1666646164; bh=jxo1Z1Le67lS9AdscC0GfL4BVLgxtuyyC1XhSB5iR6U=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Content-Type:DKIM-Signature:DKIM-Signature; b=WVNXUTO8b31BiQRqwrFuYrRRUlZYdkPxIbYgHvdfErd8W2unSZPicnKTPgkx9E3MEA0cYSuNcY zDp9Lrw7fW/DoZBC69CfWWWHb7HIE9bRK+JQ4a2IIyG4+NuGnRF95eC3KmT3qkA2w+gPy0HXm+ bcOdJlnl/MLwfJJO21e/ZZzBIualiBefFwniQDVnvGmR617jlMz+Z4td6byZr29mSiPt4FPZMy wfDVWRURFChnNQqb8TklpvNgxAIFGcjUbXVu4aGqS5DoSI75++TGM0fcEZhhunAxKOEER8QzNE A8U2tR8kDuhJHsnKzzJoCg4KgO0uxXl38HPZ/R6RvZJCgA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:From:References:To: Subject:MIME-Version:Date:Message-ID:Content-Type:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=rE37Lk8VuEhphr5nBEIEHLAXNs2E5iAtuhGps6zFzC4=; b=eQUNbjUgMB+bLb9uv1MEPACjRy 5zLnkY6ibC4TOiAr/y9+iN8WLflGTOvpi/8R5hf0YpE3ZxH5HfHASrkNgylx4ILoJdo0SEWNNkfHD qr1kUB5GPVHaBtvTholno3w2afSgJfiMbdcw1Ck4VxzZKxlJpDzP9i7B165oP77vqmC8vjQsTNDBV G89HSA4MCp/58Ul3Nv+3fzyd93CidotK1dVLWngDlm2qisfSv0cmNQ3NIvYjs5VlzHT3GPCXTZLDC QDDJbEKkbMLOSYRsXRZI2usxC+UWyyWT6T8juUmcbUCTi3adMGlhwAvmwyGQrDduljr7GDvQeR3QQ MvOJFs0Q==; Received: by zero.zsh.org with local id 1on4ni-000HhD-VE; Mon, 24 Oct 2022 21:16:03 +0000 Authentication-Results: zsh.org; iprev=pass (iris.zentaur.org) smtp.remote-ip=198.58.127.206; dkim=pass header.d=zentaur.org header.s=dkim20200120 header.a=rsa-sha256; dmarc=pass header.from=zentaur.org; arc=none Received: from iris.zentaur.org ([198.58.127.206]:43478) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1on4n9-000HLd-Ly; Mon, 24 Oct 2022 21:15:29 +0000 Received: from iris.zentaur.org (localhost [127.0.0.1]) by iris.zentaur.org (Postfix) with ESMTP id 4Mx7C221wBz3wZj for ; Mon, 24 Oct 2022 21:15:26 +0000 (UTC) Authentication-Results: iris.zentaur.org (amavisd-new); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=zentaur.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zentaur.org; h= in-reply-to:from:from:content-language:references:to:subject :subject:user-agent:mime-version:date:date:message-id :content-type:content-type; s=dkim20200120; t=1666646125; x= 1666649726; bh=jxo1Z1Le67lS9AdscC0GfL4BVLgxtuyyC1XhSB5iR6U=; b=d xpvDmNMGjGrcZJVF5GGdBj1abywn9HYBXy76DDC6rrQePjBwU5m12UO2yNbetW5T WEk/Q4WdI30BuojJJZHHDO6moIsWuOatS2RbeBfXv3YwRvBVTIAnFYO2q9k988Ao NdQ85EqQ40vMlGKClsqVCIeXuFS2o5KEUxuel/o5c/dQ8FcAuX2mq3j+oM3HmEe1 fwvOrrcdwctl2KMwdLd4RnUJ3J0GQdv3Ld8x90kxs8jlt7FYdUu+E95SqFLTB3wF J71TsgpN+4xpKgBIXPWCD9pifbF6XYPd5+kaOrpMwZ0y8q0mMn5WyJI7fHoMm0bx 7C/QXkWFjt7M/OoNk/Nsg== X-Virus-Scanned: amavisd-new at iris.zentaur.org Received: from iris.zentaur.org ([127.0.0.1]) by iris.zentaur.org (iris.zentaur.org [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id PjiMeC_Pj4fV for ; Mon, 24 Oct 2022 21:15:25 +0000 (UTC) Received: from [10.251.9.101] (rrcs-24-173-95-34.sw.biz.rr.com [24.173.95.34]) by iris.zentaur.org (Postfix) with ESMTPSA id 4Mx7C11WC1z3wZb for ; Mon, 24 Oct 2022 21:15:25 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------6ABwoBovf5BFzW4jKdH5HB1t" Message-ID: <4d288abe-5f72-6cff-9704-e80ae4b4e07b@zentaur.org> Date: Mon, 24 Oct 2022 16:15:24 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: preliminary patch for zsh/random module To: zsh-workers@zsh.org References: <08cb4c65-acd4-ba91-d82d-b8f3943aed8b@zentaur.org> Content-Language: en-US From: Clinton Bunch In-Reply-To: <08cb4c65-acd4-ba91-d82d-b8f3943aed8b@zentaur.org> X-Seq: 50836 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: This is a multi-part message in MIME format. --------------6ABwoBovf5BFzW4jKdH5HB1t Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable 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 =20 >> 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:=C2=A0 What's the use case for returning or printing= a >>>> block of random bytes?=C2=A0 Why does this need to be a builtin? >>> Mostly because I see constructs like read -k6 -u3 3> ... because? > > I did it to seed rand48.=C2=A0 Roman did it to generate a 32-bit random= =20 > integer.=C2=A0 Both of which are obsoleted by other parts of this modul= e. > > I'm sure there are other reasons someone might want to read more or=20 > less than 4 bytes of random data.=C2=A0 One that comes to mind is=20 > generating a password in a platform-independent way without assuming=20 > perl or python. > Here's an example: randpw () { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local=20 chars=3D"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890@= #%&()" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local tmp =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local -i num =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 num=3D${1:-10} =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 getrandom -l $num -s tmp =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for i in {1..${#tmp}..2} =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 print -n ${chars["16#${tmp[$i,$i+1]}"%${#chars}+1]} =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 done =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 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:=C2=A0 Treat SRANDOM like SECONDS, in that you can change= the >>>> type from integer to floating-point.=C2=A0 Then maybe the zrandom() = math >>>> function isn't needed? >>> That would seem confusing to me, and too easy to forget which state y= ou >>> left it in. >> You make it local so you're not leaving it. >> >> () { >> =C2=A0 print $SECONDS; >> =C2=A0 () { >> =C2=A0=C2=A0 local -F SECONDS >> =C2=A0=C2=A0 print $SECONDS >> =C2=A0 } >> =C2=A0 print $SECONDS >> } >> 56 >> 0.0000050000 >> 56 > Still seems like something you do because you can rather than because=20 > it's intuitive to the user.=C2=A0 Also, your example assumes you'd only= =20 > want to do this in a function (or wrap it in an anonymous function=20 > just for this purpose) >> >>> zrandom was meant to be a replacement for rand48 >> OK. >> > > --------------6ABwoBovf5BFzW4jKdH5HB1t Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


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:=C2=A0 What's the use= case for returning or printing a
block of random bytes?=C2=A0 Why does this need to be a built= in?
Mostly because I see constructs like read -k6 -u3 3</dev/urandom
... because?

I did it to seed rand48.=C2=A0 Roman did it to generate a 32-bit ra= ndom integer.=C2=A0 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.=C2=A0 One that comes to mind i= s generating a password in a platform-independent way without assuming perl or python.

Here's an example:

randpw () {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local chars=3D"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890@= #%&()"
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local tmp
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local -i num
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 num=3D${1:-10}
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 getrandom -l $num -s t= mp
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for i in {1..${#tmp}..= 2}
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 do
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 print -n ${chars["16#${tmp[$i,$i+1]}"%${#chars}+1]}
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 done
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 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:=C2=A0 Treat SRANDOM like SECONDS, in that you can change the
type from integer to floating-point.=C2=A0 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.

() {
=C2=A0 print $SECONDS;
=C2=A0 () {
=C2=A0=C2=A0 local -F SECONDS
=C2=A0=C2=A0 print $SECONDS
=C2=A0 }
=C2=A0 print $SECONDS
}
56
0.0000050000
56
Still seems like something you do because you can rather than because it's intuitive to the user.=C2=A0 Also, your example assume= s 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.



--------------6ABwoBovf5BFzW4jKdH5HB1t--