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 15293 invoked from network); 23 Nov 2022 02:59:14 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Nov 2022 02:59:14 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1669172355; b=mjF7T8KemrcEK1fPU7UOdyf5uqSoVQpJj8VSvItt1l7eJVkYmPFRAj+VYWts65oiM2A6WRN2g8 G2Wue1w/LBdYQbVPy/vYUVeLbnG09Ifxy20h1GeJ9d4gTfr5eH06KAwXhoIAWWAwveUFpczz2m 7ksrbkyaWyPzzAmp2af0cTihHkGZ2DqzBXWTv5jn7QVOhr/suMIBaqC97n9f+8hfiRQ3aYWuBi OCrfjIrtBBKTGWmSsbfjb4RggEM1h4kX89iD1wbPM3aPEXvUlrFVx2S5LEF7izAqTciJghpkFR vFyMI5TEMKl/vX8YKa5T3SHNz4WaEwJtkmnWJb3/q01RTw==; 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=1669172355; bh=qkSKVRrcMEJA8K+NB2j1hrRs2/IjMOcl4dTYYmBqnDQ=; 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=RVei5Bb8jjQiRdQPJooCB6+6KxSt01anFQTSXjxvGu38kJiMHss64UwsiRP9El99Rn4uE0oHyZ 3ttcWmvULqqyviu2DOxj8l/CuDPZgfj1BmKXwuoDIgy9a9WjSSLFoOrEXYXPwh38ivinWa+nxI tZy67ZgKbhtXHdKv9ZBI6Z0hHrs5O5sDniQ5LTuM/DJf8EOFNbShXsulEVQibeleap3F3bPij7 lz4J0Lfcpoiz65gpGGp49UT75/hi7VBMiJpnol7PJMipWvlzT6cqMD353KqFL4bC2hLGriJUg2 mu/oawMpvzU6A3jVXDDqkE5rI3m1Xq9lWW0bE7ofA1iaXA==; 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=qkSKVRrcMEJA8K+NB2j1hrRs2/IjMOcl4dTYYmBqnDQ=; b=Ts2NxKVE/aPuLYJLDwzKUOddlv 21bVBjHF/9ukOxcdTAkjO2xeKbQXWW+aqzE+3ti8ljf2jog+eWyb2MwqMNXUKIpkWYcY4Ed6m6ncU x7UNYgT9iXnfHA/iW35fvv58LnsIV7sCrMiJF3kaHgVV6ZDGb7Pt8MZLvYoMCu+6+zkzJuoU2VkBk ZhfJx3v2SesC32iTwCRk9jrftHozb8Dcvr2MWLGPHGPCCcpmWWRNHitH+uHjA1nbHEifnvfaNpOxO 0EkaDJTFTTarJiqbD7eaVnAIerxUMJEnOpfH5dHMMVysdMabRJKKS/hzr+noAiJzaTPFh08THI8Hd rHDoRwXg==; Received: by zero.zsh.org with local id 1oxfyk-000H7y-9V; Wed, 23 Nov 2022 02:59:14 +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]:36866) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1oxfyC-000GlC-O2; Wed, 23 Nov 2022 02:58:41 +0000 Received: from iris.zentaur.org (localhost [127.0.0.1]) by iris.zentaur.org (Postfix) with ESMTP id 4NH5Rg35X1z3wZj for ; Wed, 23 Nov 2022 02:58:39 +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=1669172318; x=1669175919; bh=qkSKVRrcMEJA8K+NB2j1hrRs2/IjMOcl 4dTYYmBqnDQ=; b=DRPoY44AEpFvOrDL0Xea73E8+/G2PRqnWoBX6d7/MD+h0vvo 31N23lAKqeHBU4XH+rYWIpbkdC6GSbuCMxJAcdXNWhmiUAV2b3yzdp7VLxT6HDx9 Rnin/a7U4HFi2hZjVMUxcfL5mQ+bX7q3fbj8v8WVq691KVwQZy3Oau1vkK5mHgXv 27BRLidhlBfFdcCNWaueJH+RMj+MHHCp52SWUi7plzpb3txFoifqFgVxzURfSYWQ /5ygIvcNUw+w6bZJz27FV/Gg6I9PVU+SAaQsf61oKOfaKxfPSuUM1jxxlWDn1LJj cmQtEzqFfLrHd2bj91QkTnXwLxUcoeG5qCnSeQ== 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 UySf90efYNU6 for ; Wed, 23 Nov 2022 02:58:38 +0000 (UTC) Received: from [192.168.72.136] (unknown [136.50.213.220]) by iris.zentaur.org (Postfix) with ESMTPSA id 4NH5Rf3Sw9z3wZb for ; Wed, 23 Nov 2022 02:58:38 +0000 (UTC) Message-ID: <2df1001e-69a6-9785-70a6-8416fdcffd8d@zentaur.org> Date: Tue, 22 Nov 2022 20:58:30 -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> <30a7e749-7f30-ecae-6479-a345b1682e7f@zentaur.org> From: Clinton Bunch In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed X-Antivirus: Avast (VPS 221122-4, 11/22/2022), Outbound message X-Antivirus-Status: Clean Content-Transfer-Encoding: quoted-printable X-Seq: 51028 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/22/2022 7:23 PM, Matthew Martin wrote: > On Sun, Nov 20, 2022 at 08:57:25PM -0600, Clinton Bunch wrote: >> On 11/20/2022 8:21 PM, Matthew Martin wrote: >>> If a uniform random function is desired in zsh, I think it should mir= ror >>> the interface of arc4random_uniform: just take an upper_bound and ret= urn >>> a value in the range [0, upper_bound). >> The original implementation did exclude the upper bound, inadvertently= , but >> after discussion it seemed that was counter-intuitive and something ea= sily >> missed in a cursory glance at the documentation.=C2=A0 Adding a lower = bound was >> easy enough and saves extra shell code even if it's not likely to be u= sed as >> much. > arc4random_uniform excludes the upper bound so it is a direct > replacement for % . I think it would be > wise to follow an established API and avoid off by one errors when > refactoring existing code. Similarly it doesn't offer a lower bound > option since that's trivial to implement and difficult to get wrong. Instead you get off-by-one errors in new code because people assume the=20 specified limit is included unless they read the documentation closely. > >> yes, much of getrandom *could* be implemented in shell code, much less >> efficiently.=C2=A0 For example my precmd could save the math eval by s= pecifying >> getrandom -L 1 -U 7. >> >> Once you've written the code to access the kernel random source, it se= ems to >> make sense to me to make its output as flexible as possible.=C2=A0 I d= on't get >> the concern about backwards compatibility in implementing a new builti= n >> unless you know of an external command called getrandom that is in com= mon >> use, and that's easily fixed by changing it to zgetrandom. > I disagree on making the output as flexible as possible because there > are already features in zsh to get those formats and the API would need > to be maintained into future releases even if seldom used. I think it > would be wise to start with the minimum interface necessary and then > build off it as uses arise. > > Interfacing with libc and the kernel to get random numbers is something > that can only be done in C and SRANDOM builds off an existing API, so > I have no opposition to it. I can accept that uniformly distributed > random integers is a useful and non-trivial task, so probably should be > included, but would prefer an existing and proven API like > arc4random_uniform. > > I have a patch based off yours that implements just SRANDOM and > a mathfunc for arc4random_uniform, but haven't yet had time to test it > on multipl platforms. Even if we go this way,=C2=A0 I don't think the function should be called= =20 arc4random_uniform.=C2=A0 It only implements the arc4random algorithm on = *BSD. > > With just SRANDOM and arc4random_uniform the features of getrandom can > be implemented in a script. I've taken a quick shot at a proof of > concept below. > > [snip shell code example] That's a lot of zsh code, most of which would be difficult for a non-zsh=20 expert to write.=C2=A0 So it would need to be provided as a function and = then=20 you're left with the same support problem, but a slower implementation=20 that keeps converting strings to numbers and back again. getrandom doesn't need advanced zsh programming knowledge to use.=C2=A0 T= he=20 -U and -L make it easy for a relative novice. arc4random_uniform is a=20 programmer's interface, not a user's interface. You also ignored the zrandom function which is definitely non-trivial to=20 implement in the shell.=C2=A0 It's not even trivial to implement in C.