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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9716 invoked from network); 23 Nov 2022 20:34:11 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Nov 2022 20:34:11 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1669235651; b=Fh6uhqK7rC5dOblMdRzd1uEpgC4DoARayc16DgQ2WbyvT/NYQ6MELsBKgekpq5zH7/Wz8WQ1dZ spvr7696gRgzChMPod2fHB32aGQoJMYWxwm10aSP/97FACm5CU5iaSzje9Nc6LWJEUp9NVJfHl Yc1nYIsHtk0ryHMU+YwG5I73xv6/s317597wpeYYEqS0QQOFta0bj3ytjOSKK+DiJR091Saqkg LK/EgF+C7EF4zeid+R9U/KjIfpHtNdN+/ZVoYuCjR5CFeZWf15Mgt8ny22Hji7MXqX8QldyeOV gyxHoxM+8sluwv6RbBgtXFEwK9ZSKk68I/dk+/pWmok7iw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out1-smtp.messagingengine.com) smtp.remote-ip=66.111.4.25; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1669235651; bh=bIcA6BL5XmQjPbzuEXT8NP7i3Dd8HGTYo/7WVE6PPBo=; 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:DKIM-Signature; b=GY26e+Y3cAKSyElMlJWql7FBbjei2XA2HfO9++pLCuryE/PtxG7UvOGTl/xM79sEwDHI8vsv9n wxmhhoQRXFFcv5uJnbg/40D0NijfliZXmgeC4H38Kph5OOgKqH1bqArhq3mPQG5PC0sSUeuSTz KMF+82q0uRpWgeRuQbVtWbU2vjnf5nDF2hJSOw3z/gIts2RktQVmfAa22opCyoZpS7CsSkJ/D5 QZ1u8xMjPkpjJtuQ4+EonSUqTYOlQwZt05X17gSmFchVbMXEGMmRnyqc2Vlg1lBihYae+3Cwvt //FjeImem3BgX/npx16lWW51b6ueE2iV6EC0W6Mjd8UJhQ==; 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=BqsBuUyupyV4ljvJY8YmVlrF3Kww/aIXol7uitLuYnA=; b=dH8mktNphR11svX3ltL+udQTEd UtZAs8oNVG36ZFV8xpFQniyO60EbsqXiZipjjzRmL79Fj0nsbGUx4W5ZC63G2maijwouEy4iMbLmV 9SuHT43T0bCMOUa/UdvcG/BJtPF9XFapMNQpuSmKiya1nUSmRVMJxa/AFJFIy4TTKBEUkV+JriDRQ mJTry3lW5iWEk8RLYLdUJvSQwWPZw+mtWNZjOIe/SykC3zpMyL9L74cBMwweVs5MIt2eIyR1+AJ46 hn4erLo4YdgXAuTzyZmVsKj8Q3mOFgPhXHefUhwzerhNNN7GRUHwgfBTeqi5bm7F78dFWASZBc+YQ UhY1ucDw==; Received: by zero.zsh.org with local id 1oxwRf-000NNA-7i; Wed, 23 Nov 2022 20:34:11 +0000 Authentication-Results: zsh.org; iprev=pass (out1-smtp.messagingengine.com) smtp.remote-ip=66.111.4.25; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out1-smtp.messagingengine.com ([66.111.4.25]:35243) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1oxwR4-000N2c-5V; Wed, 23 Nov 2022 20:33:35 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 720755C010C; Wed, 23 Nov 2022 15:33:33 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 23 Nov 2022 15:33:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1669235613; x=1669322013; bh=BqsBuUyupy V4ljvJY8YmVlrF3Kww/aIXol7uitLuYnA=; b=KcMQ/kDQy5Chm5XV0I54Gs1AQl mfhDi+myLSe99fZjx3iYxh0TAfLHTSK+9b0G36bepY6Np1ZFKjfYXOLJtoiWcM5k SuL3BLyl/p7sNnShCrQxZrh6xObbw/ZM6neS0d5ddpqiXWsHuW6o/LJ5jt+j3ACO kw3hvOok5a0m1Gs1oLAEdTd5AiagUx7AJlhIGwNjX7ht4/f1LCkOIqNSVliviVWY 3pTOvmwU+7J9lUrIP1aoXt/S8ib6fyw+efNntxG0qJRIkgsGw2E+rh9RktpUwPfg zTK4xYipIBSNuNkromny6D1Uz9xjOif9kZCiZ0jc3a11ThAiyDLmsha+iMfA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1669235613; x= 1669322013; bh=BqsBuUyupyV4ljvJY8YmVlrF3Kww/aIXol7uitLuYnA=; b=j uAszcR5WDKraMfGlPjwNN1XemVq3TvlIHPtnf5NzdLvNMRweii5H6wz0URW9jU9S HgnMFcNtzjra7WWHSnRu6yNwTtxwnOW1kc6aSP7c+oFyXvNSUrWtnXGEtWpGSrha pP75kBnbJeDPtAxdHomPOqJcsxkWlOzRMoX1EVQt7094GvegUTsameTM0EBfP8e0 CYtnvODYXHs5UofgHwvfQj45h8obKW2gzUchtDy/fPCJynwq3w2FrxxkfpESqFK5 dfRfC0np/2ybo/D3p+8KCtIlJxBO0iOGue3F50iF7hFEhYYxgc3L3gs/tv7RpU5n 92rUaBjB8IlGTDL3Wv8Lw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedriedugddufeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtugfgjggfse htkedttddtreejnecuhfhrohhmpeffrghnihgvlhcuufhhrghhrghfuceougdrshesuggr nhhivghlrdhshhgrhhgrfhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpeehheejjeevte eijeefjeevleffhfefteetkeeghfdtueeiueejiefffeffhfffteenucffohhmrghinhep uggvtggvmhgsvghrrdhinhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Feedback-ID: i425e4195:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 23 Nov 2022 15:33:33 -0500 (EST) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4NHXrn5zLrz38Z; Wed, 23 Nov 2022 20:33:29 +0000 (UTC) Date: Wed, 23 Nov 2022 20:33:29 +0000 From: Daniel Shahaf To: Clinton Bunch Cc: zsh-workers@zsh.org Subject: Re: [PATCH] zsh/random module [UPDATED] Message-ID: <20221123203329.GP27622@tarpaulin.shahaf.local2> References: <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> <2df1001e-69a6-9785-70a6-8416fdcffd8d@zentaur.org> <0a07afaf-1194-6752-8133-8aa6b689724d@zentaur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0a07afaf-1194-6752-8133-8aa6b689724d@zentaur.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 51039 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: Clinton Bunch wrote on Wed, Nov 23, 2022 at 07:41:40 -0600: > I don't think we're going to come to an agreement on inclusive vs exclusive, > and I know you'd hate the idea of both interfaces, so others will have to > weigh in. Some considerations: 1. What existing API, within or without zsh, should the new builtin/mathfunc be consistent with? 2. Is it the case that choice A can be implemented in shell code in terms of choice B, but not vice versa? [For instance, if the argument to -U were a uint64_t and were exclusive, there'd be no way to specify UINT64_MAX as the upper bound.] 3. Inclusive is necessarily the rule when sampling from a given set of elements (e.g., in zsh terms, "here's an array name, gimme a random element from it"; when the array contains, say, {January..December}). In this case there's no need to involve integers at all. 4. Which approach generalizes better? --- [Please consider these questions for a second before reading on; my proposed answer(s) are below.] --- For #1, we might want to be consistent with the subscript slice syntax. $foo[4,5] selects $foo[4] and $foo[5] both. Similarly {4..5} includes both endpoints. Also, I could be wrong here, but isn't it the case that exclusiveness goes along with the lower bound being hard-coded as zero? That's how it is in modular arithmetic, in arc4random_uniform(), and in Perl, and even in C's idiom for iterating a dynamically-allocated array («malloc(42 * …)», followed by «for (i = 0; i < 42; …)»). Python has both random.randint(), which is inclusive, and random.randrange(), which is exclusive — but the latter mirrors Python's array slice syntax, and that syntax has a special-case form for "All elements from the Nth through the last one, inclusive". I think I'm leaning towards inclusive if -L and -U can both be specified and towards exclusive if -L is hard-coded as 0, but I'm happy to be convinced otherwise. HTH, Daniel