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,MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31339 invoked from network); 21 Nov 2022 02:57:45 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 Nov 2022 02:57:45 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1668999465; b=maVg5qD+S64h5cy/POxF3Mh7Ff0sFQwsGhFjqSPxB+cYG2sKp7rltxUqnYFnKnX3KEoLYY2e5M DuQIY+PDXEbr2U5L/oQ49KcVCjIaycTiffyPyyHOOdsTEWwdQFMhyuqX3gVBFS5wIB4zDOJ6mN rZk5HiGij2vmILaOYK2ZcHDAhZgV3aLfxJd8FQHBTdW1oxiDBwZ6kP+3JrHHUuf+syKagiSDE1 3e5dmMgDF3cZ+H8G2QLxrUjdxdAZoUKUzGIk9eFh0MquyXgIt8e5n+Hv1933+EgrQCWT/tsRKp z7wbRzpFRaTUa/VcHNq15pWrnvVYFxnJpCGfwq9oqY9l0Q==; 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=1668999465; bh=VAaKblQJyRvahtYo1SGe6D3qBypJRdXvBL4jV8mQGC4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:To:Subject:MIME-Version:Date:Message-ID:DKIM-Signature: DKIM-Signature; b=nZTzW1EAXaNn0H0yYXpv734MRUzv8OK7t2aFAEarTBy7IXS9N19jn/+QBUEgFz7K1zYFf+JtyR jo6lBlUpRRNr1J3BjVb7Ci0hXr3KoiJ82UdYYTZuyCD9siK7/VGN3BejnrvQwWSXQk3RTp9wLZ AIN/MqNlEtg9vVjpnEzNYpyBzI2IYZXoljFkb4sYTYbw6xIRRpM0mSjavylDbCqoYHpTqwEQDo 1nf56U/rU7T/kWucPTnw/e6DVqvZgkEYIGIb3oM2iR4yFDVT4x54umykd9SjQXAngj4eO91ctF JPM7AnJ2yUZ8kb/aPjezaDsEsGSeIQZE0/77B4hetYIGpw==; 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:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=MRENtP4eELbvoSPGrbuyhJckdiraJ/sVlV721ezMgtU=; b=oH0sJr1NFbFDWwJH0japSR6FMn OQfKH9/spblwq6Hu+g7YE+DeOf5+En3TazavGQkfnuHFzXFa+i5CivNFBGYqTl77knxkDxhmhyDmt wogoldsIo0KuzlgHf/wK55yG+aexeIP09aBaXHby5jbtitVVUCShZ8iMIj9c589JIeqkb57j21xsX FNKIsWNWzqFEjWkjFQdB9Mtgt4qK2Vf5Q3Zm5JJVvdyGH3j4fxDBA5YFHzcFXcGPDkFdUmei9+wML jYWND6p23Uh3+C1e8q60X619d9l3mR5PASpPSz9nAp/5S7KnrJqtOU7GOrKWAFGeMh12HqZXUPWUG n2/GtOFQ==; Received: by zero.zsh.org with local id 1owx0D-0006I7-Ex; Mon, 21 Nov 2022 02:57:45 +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]:36764) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1owwzu-0005do-Ij; Mon, 21 Nov 2022 02:57:27 +0000 Received: from iris.zentaur.org (localhost [127.0.0.1]) by iris.zentaur.org (Postfix) with ESMTP id 4NFsW92WLxz3wZj for ; Mon, 21 Nov 2022 02:57:25 +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= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:references:to:content-language:subject:subject :user-agent:mime-version:date:date:message-id; s=dkim20200120; t=1668999444; x=1669003045; bh=VAaKblQJyRvahtYo1SGe6D3qBypJRdXv BL4jV8mQGC4=; b=jD5pQr9qGV9Zqk2glleYoEffeveYT4SNjc5ZAbLWeq1IxSxW uiPKRQYbLpboc2ctEYGTjShpMImkBQlyZmB3AIYZbkOEJiV0xJQIQ06bkQlSGIGz xwHYuQzffj2qT02A0Z0euW8qTtq0YUK9GiU/hzurfLrYFBE4VJWY+2ZPLw7grGNb ifeldMtuWn2CexbpNt6aNl7lkaB65vCJgWG0WlJuktzdWZh+uZzCAH2/hyNUfL9y Ec8BghouCxeSsBk9nYSDGLGoHD8so5tHUlCbtD3agVQdtIzWcVtFPphNZGmpQ5Do bjun85c4HP2hgj67NZv7MsQ3JymcgT6xy62Ozg== 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 q7gbvQcXDvdO for ; Mon, 21 Nov 2022 02:57:24 +0000 (UTC) Received: from [192.168.72.136] (unknown [136.50.213.220]) by iris.zentaur.org (Postfix) with ESMTPSA id 4NFsW840TVz3wZb for ; Mon, 21 Nov 2022 02:57:24 +0000 (UTC) Message-ID: <30a7e749-7f30-ecae-6479-a345b1682e7f@zentaur.org> Date: Sun, 20 Nov 2022 20:57:25 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] zsh/random module [UPDATED] Content-Language: en-US To: zsh-workers@zsh.org References: <741b77be-b679-76cc-f8ec-49c9d89323c1@zentaur.org> <1e8ea669-7a25-b321-6024-72dbc43ac023@zentaur.org> <41205a86-8aad-4821-baa4-1d2ac9bf3c5d@app.fastmail.com> <1b2cafe6-b4b5-c59a-11f3-4dbc1e99e2bc@zentaur.org> <6275a5ac-3a47-f591-7b3c-380ec4fed5ac@zentaur.org> <3423b634-a7c3-9efc-92cd-b9b995ac1c27@zentaur.org> From: Clinton Bunch In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed X-Antivirus: Avast (VPS 221120-6, 11/20/2022), Outbound message X-Antivirus-Status: Clean Content-Transfer-Encoding: quoted-printable X-Seq: 51007 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: On 11/20/2022 8:21 PM, Matthew Martin wrote: > On Sun, Nov 20, 2022 at 07:59:54PM -0600, Clinton Bunch wrote: >> On 11/20/2022 7:07 PM, Matthew Martin wrote: >>> I'm not clear on where the getrandom builtin came from. I understand = the >>> desire for SRANDOM to have a proper random source in the shell; howev= er, >>> the rest seems like feature creep that if necessary could be implemen= ted >>> with a loop. It seems prudent to keep the initial module to a minimum= to >>> ensure there's a usecase and so backwards compat concerns don't crop = up. >>> >>> Would it suffice for your uses to have a module with just SRANDOM? >> One of my use cases is in precmd to replace this function >> >> get_random() { >> =C2=A0 local retvar=3D$1;shift >> =C2=A0 local max=3D${1:-32767} >> >> =C2=A0 local out=3D$(( int( rand48(my_seed) * $max + 0.5 ) )) >> >> =C2=A0 eval "${retvar}=3D$out" >> } >> >> used here: >> >> precmd () { >> =C2=A0 get_random cdb_fg "6" >> =C2=A0 psvar[1]=3D$(( cdb_fg + 1)) >> } >> >> A better more uniform distribution of random numbers can be achieved w= ith >> >> getrandom -U 6 -s cdb_fg >> >> than $SRANDOM % 7 which will have a modulo bias > It's true SRANDOM % 7 would have modulo bias; however, even if only > SRANDOM is provided, the out of range rejection loop could happen in > shell code. While that's less convenient, I am of the opinion once > a user needs to care about modulo bias, they're likely better served by > a language other than shell. Why write an external python script too generate a random password for a=20 service account when you can do it with the shell you're already=20 running, especially when python might not be available? > > If a uniform random function is desired in zsh, I think it should mirro= r > the interface of arc4random_uniform: just take an upper_bound and retur= n > a value in the range [0, upper_bound). The original implementation did exclude the upper bound, inadvertently,=20 but after discussion it seemed that was counter-intuitive and something=20 easily missed in a cursory glance at the documentation.=C2=A0 Adding a lo= wer=20 bound was easy enough and saves extra shell code even if it's not likely=20 to be used as much.=C2=A0 I can see the first question from a user being = why=20 can't I specify the smallest number I want?=C2=A0 I'm already getting use= r=20 complaints about a limit of 64 on count, even though that's unlikely to=20 be exceeded in practice.=C2=A0 I'm also anticipating complaints about not= =20 generating negative numbers. yes, much of getrandom *could* be implemented in shell code, much less=20 efficiently.=C2=A0 For example my precmd could save the math eval by=20 specifying getrandom -L 1 -U 7. Once you've written the code to access the kernel random source, it=20 seems to make sense to me to make its output as flexible as possible.=C2=A0= I=20 don't get the concern about backwards compatibility in implementing a=20 new builtin unless you know of an external command called getrandom that=20 is in common use, and that's easily fixed by changing it to zgetrandom. >