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,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28003 invoked from network); 21 Nov 2022 02:27:52 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 Nov 2022 02:27:52 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1668997672; b=o8nQ17k+4k+12+HQ5y19nNxPbxc1jgAYSmdg9uq9Q0Yn3UuN0o4NaFccqk8i0YQIij8hGBbZT4 gw3VDMJ2x9vVJTZWLa57DPMi5CIYADqebLShQV+WVxJ9x0B4f3u4kbFYMjAmxLTzXzoMHM7O12 gX/LYNsO+PVvMYol+B3w/t57eeOCqU8cEJ+4wtClJnIAzocfL93n22C5N9Vz7hNQMwgxZUzi2L vHu3S9hbfV1YSsQyIihZkRntTSUaiNiYCjZqY1DsRCyErsDqLvdzEquujBRvpmzfu40LIiD+98 nYi0BIZJa6Ng1bBNnrpXMWDzmbSGRvsaavZuXxBXAuCpgg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ot1-f42.google.com) smtp.remote-ip=209.85.210.42; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1668997672; bh=Kv7SsbkwKYQUve2oU4v2uXpBgLbgJShWpKU9YwGpzE8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature; b=WsyccUsEjkvbpEsJ2NDUlwJrIHJFdGnb28E7ExvHWSDZjfjL0zENxhxc88tdyHg7m+57Af6bj8 0WwnBKKt4jlT/GZr/JDCL6R9cLeSN8zL3t9TBNYuq4EE/xo73F4vgflSaNCr19iGbFAdU7AZKv X7fbueNVV2T5o7EDQodVwYPLzSunfdB25fzIcl9Ov1H2g1TNtBxNgn3jYItmNw5z12odPe5vI/ EH+FnzBdJ1rvE7zluGHovF+ijtN1R7Xgb57eiMMd4zw5xLgE3b+XSd09r/i7CnzQ9+qr0sA6D8 B6PDBH7ho0L+P1YeEe/3QLYOU+MK76+zuonKZI6Y1r19QQ==; 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:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=wMgO07JVTDYW6EPaITEy4gRk/I9w/dV2+4AOnD90/wU=; b=j23mI/P021syzoZ3/haxgGBC7z SB5XF97R+ZvjHvxIRg7xClM3m6Mrd1FRxsqlkqekIF7NRucLpYfaQjE6D7BLCD9u9iN4KNcoibSyB exPMIyxE73Vq/i7KI/kuHc5Swh7+b7YJ4HSbU68DmqP0Z6qFxy7kkyjhLJ+30Nxz7M4ZQt6dyDy5S syhhz0vsKjJ4tLHSZUZ5HDp/yRIrbi6+hRKtmc943R0RxwhagdKf16jmQspqfM6nh+/6K39mMkqBc d2CMk63XOg6mMM3Lw711DxXyil+xw8eWGhTdXInzfD/T0plPAS5KC6e9oDMYoNuR6K8ljEnaiVTOM 3ZxXcX9A==; Received: by zero.zsh.org with local id 1owwXI-000IXA-Rp; Mon, 21 Nov 2022 02:27:52 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ot1-f42.google.com) smtp.remote-ip=209.85.210.42; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ot1-f42.google.com ([209.85.210.42]:41793) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1owwRM-0008Ou-Qj; Mon, 21 Nov 2022 02:21:45 +0000 Received: by mail-ot1-f42.google.com with SMTP id p27-20020a056830319b00b0066d7a348e20so6567050ots.8 for ; Sun, 20 Nov 2022 18:21:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date:from:to:cc:subject:date:message-id:reply-to; bh=wMgO07JVTDYW6EPaITEy4gRk/I9w/dV2+4AOnD90/wU=; b=gxj/Mbkr95X3BRE7kqDuOA+3q7actcKAtIswUdPw200fjg9vXRDFBeVTkIxM4i+bPh Ba3H8qCxJSQZn08iNnLV9C0/vQ+5sCW3cVtP0sdS45xuyVQF6DieGiPQzqWLUTaMDJtV kksm/dJcni5OeusOP8y247CuKGDlR4DwlZPG/w7KaNMg854aWvn/MijK1/bYkAzrxJQA qlSWa3HBr2QcJotGjsw3qwt8sjpkvYvmS666KoqneiOa5niVo2zBVxhn6/whQgG/xrd8 hTzfzIe2ZFGcJRn2s1ahUNcB5TO1SFMqiWouRCR/+pRYE500fYqlmDllVN2PEsxu7Axw NF2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wMgO07JVTDYW6EPaITEy4gRk/I9w/dV2+4AOnD90/wU=; b=dwLS3vaikh4P5bLA2LteXZizl9PI4Pc3ji8LcfhPqHHwB1RNokxanLH8aP7VkgdHHa Xll3M03ivz7ngsrd1XCXF1LvxdQEtx2gSL/+x881kUloekv0pk7wgYKPLXMB5vmHdvHp TEXU6pD0zaPeH37njyMmjSZTu3ZCo/uHKRU04SZ2m4wvf6sTQdf2dmQhmbtNT826Qgrj ZhwAGLDYeF5KGPFT5+NaOHvOdo7/Z58kND16EMBT5PMTKEAHZPKawHXMXrX0zRGVapLv kUVpZxMz/DomYGdi2G04meQ+U2rTWYE2Z7JljpS6Vs/seq4xUxKdxgfRSnO+J9TJ4XS2 qJWw== X-Gm-Message-State: ANoB5pndLvIaAIhL5UKflQ5RSzkWwFxzZkCOKEoLoBdhFCxX0WgDnqIw Eac6IHPYp1GEdggaIlYGdwc= X-Google-Smtp-Source: AA0mqf78/G8lho0VhchSOL+mG8YcETRFKl1JXBtMpc+dQ3xAMNWe9mA0YvxOmCCJpmmfcNGdQ3z4FQ== X-Received: by 2002:a05:6830:3697:b0:66b:e4f2:7f2a with SMTP id bk23-20020a056830369700b0066be4f27f2amr9022117otb.317.1668997303703; Sun, 20 Nov 2022 18:21:43 -0800 (PST) Received: from CptOrmolo.darkstar (cpe-76-184-110-212.tx.res.rr.com. [76.184.110.212]) by smtp.gmail.com with ESMTPSA id j5-20020a056870050500b0013bc40b09dasm5353068oao.17.2022.11.20.18.21.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Nov 2022 18:21:43 -0800 (PST) Date: Sun, 20 Nov 2022 20:21:40 -0600 From: Matthew Martin To: Clinton Bunch Cc: zsh-workers@zsh.org Subject: Re: [PATCH] zsh/random module [UPDATED] Message-ID: Mail-Followup-To: Clinton Bunch , 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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3423b634-a7c3-9efc-92cd-b9b995ac1c27@zentaur.org> X-Seq: 51006 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 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; however, > > the rest seems like feature creep that if necessary could be implemented > > 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() { >   local retvar=$1;shift >   local max=${1:-32767} > >   local out=$(( int( rand48(my_seed) * $max + 0.5 ) )) > >   eval "${retvar}=$out" > } > > used here: > > precmd () { >   get_random cdb_fg "6" >   psvar[1]=$(( cdb_fg + 1)) > } > > A better more uniform distribution of random numbers can be achieved with > > 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. If a uniform random function is desired in zsh, I think it should mirror the interface of arc4random_uniform: just take an upper_bound and return a value in the range [0, upper_bound).