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 16622 invoked from network); 4 Nov 2022 12:59:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 4 Nov 2022 12:59:19 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667566759; b=sSne1McrLeHikaZUwJXtFtpdzintdOJ32xh7ppBh/UMVsrbPKjDZA4PjNR9jFC1HSb4dwkyWmF oOyGqEPJOHIQF9yBgIsgtnUIiUa3G3flCvA+wYstby6kVQbq7aIgzOf3u7iSaJ3io46QcX4p3O FxUSfEAyE/naeASCYuR815WvhybOYQtY8GWswUwVdg6YL8XU4vYg5aCx/Vt05jZ9w+ZEvWp39C F/rnVksrNcrtg80THf9qkWpzVi70zvRXsg6cqjpYceEJjx1EXUbs8IYcBjOILG+Cq4hw5Ke4uc 90solhuGYuzCGSObu+iHj8oGWwLjdDkWz4zNlsGL8Cxu7Q==; 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=1667566759; bh=LIbq9uEjhw3ckpnSk0YOuNm9SB44F+cLy7JDR5FnxBE=; 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=YeQWYTkKcxjZm3EyNcJl+n+VlGfXXswtr2h25iClddYlht3PLcgaPFli2T1f3O7NSyxPnwvXok +3icZOYdWhced/OoMbjtnNV68i3Ga9BjiiBZZLmK6EHpEHoa1JDFLCRcc8fcEjm0pGctA3t4XG kajs7cnUZN9cDv9BAbDaQNwe1j6oX3WcYgqyQUZxDlhSilJv3kukHVDfTEjEM6VPHj62dP3BL0 NYun9if5MgCtnzoh1FN4peXMGbHYafnrSv4E95WUTZMxIwbUdhgvLRz5YNfptYsYMyCSGMbZmZ TY1eUiO6WeprUnrFZPxe83IazNv4nl3OukG/wgNn/GEQRQ==; 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=JxsLnajoRa47WDJqQsMsodNtxW2Yo5i+c2Qn+cTbb50=; b=HiwH7a61HGGVhjgVTdfOHDk5mv YyWWa2e8cr3QPwluPwBYoqd1POospvoNGbAa0ONGyX1kWHNtEPcKUnsisEWxPMtvioNy4t6yyhguj UHnWbwNDFr9JjNvYHBMCMIia9S2BCZ//tG8M7OgUw1jxOPVqfA5zoTIU62ODUDpCR7bdwKSADcN1h F7XhOIyJ66R0pmV+XT0TC4+O/lzy/ZCwXBLKNwSKeHpWB4Ci/Qe4wAfkfQxEX1bkHZMNFrQlaqxwI 47Tpy2qQ7zRdEosH3vekdF3/txSC4/PdoGTHKf1RDsStcACJrxzJ2pRMU5VA6GxSWE0D6SmFJOlcy jLfUVjpQ==; Received: by zero.zsh.org with local id 1oqwI2-000NCG-CK; Fri, 04 Nov 2022 12:59:18 +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]:60732) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1oqwHg-000MuY-Rn; Fri, 04 Nov 2022 12:58:57 +0000 Received: from iris.zentaur.org (localhost [127.0.0.1]) by iris.zentaur.org (Postfix) with ESMTP id 4N3gfm32H6z3wZj for ; Fri, 4 Nov 2022 12:58:40 +0000 (UTC) Authentication-Results: iris.zentaur.org (amavisd-new); dkim=pass 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=1667566684; x=1667570285; bh=LIbq9uEjhw3ckpnSk0YOuNm9SB44F+cL y7JDR5FnxBE=; b=GeiTw3EujBW/xHITpeup9ry3M8Xbh1EW/KrJpd43r2epMBW4 QhnqxYH5ul88ZXgTXE4FtQelfKre0iaWcgn1gVuc1E3tgFQBZwV13Pas0IKCfwLk OzK6Ben+cS5qQ6v7KqhVzlX3ESvvRZKLnrhUbWVECmncMP3jqII5pFLYAUsrd3M4 lTHQAraX8rA9eCmKhInSyxrAU1rlfuT7LVbAZeOjz5xVFTjyXfKLxKE8C0gSHPnf no0m04n9Uat+dS0faKX0rqnStz7eLrxGa4D8SPSTAwOqQReUu1Y8ocBjsr7VEl1v kB2RflR5ElU7IAarWfSCOlx/ihby5OqYd8Sh0g== 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 C08yiRAcbdx9 for ; Fri, 4 Nov 2022 12:58:04 +0000 (UTC) Received: from [192.168.72.136] (unknown [136.50.213.220]) by iris.zentaur.org (Postfix) with ESMTPSA id 4N3gf43vrqz3wZb for ; Fri, 4 Nov 2022 12:58:04 +0000 (UTC) Message-ID: <1b2cafe6-b4b5-c59a-11f3-4dbc1e99e2bc@zentaur.org> Date: Fri, 4 Nov 2022 07:57:17 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH] zsh/random module 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> From: Clinton Bunch In-Reply-To: <41205a86-8aad-4821-baa4-1d2ac9bf3c5d@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed X-Antivirus: Avast (VPS 221104-0, 11/3/2022), Outbound message X-Antivirus-Status: Clean Content-Transfer-Encoding: quoted-printable X-Seq: 50870 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/4/2022 2:27 AM, dana wrote: > On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote: >> Then why would you use the builtin in preference to the parameter SRAN= DOM? > I guess the main reason would be for the bounds functionality I suppose that's true.=C2=A0 It may be worth looking at making the defaul= t 1=20 except in raw and hex-string mode, though that would be harder to=20 explain in the documentation, I think. > > On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote: >> Copied that pattern straight out of Src/Modules/datetime.c > TIL. I also lied about sysread, it does the same. print/printf, zparseo= pts, > and zstyle don't. Can't think of anything else off the top of my head r= n > > On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote: >> Trying to think how to design tests when the output is different every >> time by design. > If nothing else it could just make sure it's in the expected format > > On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote: >> And I can't think what a completion function would >> complete. It's not like it's using long options or enumerated argumen= ts. > Most of zsh's built-ins have no long options but they still have comple= tion > functions. Some people use completion as a substitute for the documenta= tion. > Attached _getrandom for your consideration (assumes no further changes,= tested > very minimally) > > btw, in writing that function i realised a few things: > > * In the documentation, i think the default upper bound should be 42949= 67295 > rather than 4294967296 Wanted to put UINT32_MAX, but didn't think Yodl would translate that :) > > * Why is the maximum length 64? Also, should that value be documented? The getrandom() function itself is only guaranteed to return 256 bytes.=20 64 32-bit integers.=C2=A0 And it should definitely be documented, I thoug= ht I=20 had. > > * If you put -i after -L/-U it overrides their effect. Maybe the > `if (integer_out)` in the code should be an `else if` instead? That definitely isn't intended behavior.=C2=A0 Specifying both is redunda= nt,=20 but bounds should definitely take precedence. > > * It appears that -L is inclusive but -U is exclusive. e.g. if you do > `getrandom -l1 -L2 -U3` it will only ever return 2. I assume that's = not > intentional? When (after I posted, of course), I realized that the algorithm I used=20 from arc4random_uniform would never return the upper bound, I began to=20 debate whether to try to make it inclusive, handling the pathological=20 cases, or documenting it. > > On Fri 4 Nov 2022, at 01:22, Clinton Bunch wrote: >> It still seems weird that the dev guide specifies mixing the two. > I agree > > dana > > > diff --git a/Completion/Zsh/Command/_getrandom b/Completion/Zsh/Command= /_getrandom > new file mode 100644 > index 000000000..3513e10b7 > --- /dev/null > +++ b/Completion/Zsh/Command/_getrandom > @@ -0,0 +1,12 @@ > +#compdef getrandom > + > +local min=3D0 max=3D$(( 2 ** 32 - 1 )) > + > +_arguments -s -S : \ > + '(-r -s)-a+[assign result to specified array parameter]:array parame= ter:_parameters -g "*array*~*readonly*"' \ > + '(-a)-s+[assign result to specified scalar parameter]:scalar paramet= er:_parameters -g "*(integer|scalar)*~*readonly*"' \ > + '(-r)-i[produce random data as 32-bit unsigned integers]' \ > + '-l+[specify length of data]: :_numbers -d8 -l1 -m64 -u "bytes or in= teger elements" "data length"' \ > + '(-i -L -U)-r[produce random data as raw bytes]' \ > + '(-r)-L+[specify integer lower bound (implies -i)]: :_numbers -d$min= -l$min -m$max "integer lower bound"' \ > + '(-r)-U+[specify integer upper bound (implies -i)]: :_numbers -d$max= -l$min -m$max "integer upper bound"' >