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 6174 invoked from network); 18 Nov 2022 18:38:51 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 18 Nov 2022 18:38:51 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1668796732; b=EHqeP9jI6OAbNtS3XSEajAzg5RU1CGtZsg63iCoyRrt7xHEysBLZmiX8zP1XkzUZPP72iY87ee bPGcW8rfxI7aKwHt9Ax21Fh8YU/Te8aIadT1ExppBiqHVUQvP3UMkuZFOOY5lFsBEbET8ZFhzT J5LHKt0KH9HthZkS+kcvnUYtP3+HBuqofPOb9rzxcCGZ6uhAGvNaCFPezbDe1vaSySXcTzyHmr WQF/k1gqHQJEiCj1TZib6BcRq3PxlxRTDorTsFWqcTATNdCS2klpe/2VHJEoy3VITlWpEZEHTL wvRlu7qH4qUCXPq/yXGGj4zJI2/KDxvi84GB6zSf0UYONw==; 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=1668796732; bh=JTsE006eumsVGJTG7oKBgxN+UzQqXUdYvckOv3aTJ9M=; 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=mlKZqLFHepDTNmLAVOviZ8/fGJi6rqUwzQX0Pblg7dwVvvxGmHy9yClUWQX1rAzEeH6xWXg5k9 MiRmSUtUDVsa5wM3TGsPCyfX7pxM5AtIf4StXpfT47HRhibL8J3MN8/wLJtsaVaJekxmTnWFBC F+PxlBhKliH0n+9tEe9HvKMhwWQsoCYh6odQTiRaRveAnq1nm7ru2hA8hXOc1DZ2LyFLs9Ea1a Zpvej/B5n2oNgwcLA/g3LIDEZYVUv+TZb1KvIEnWMpFVkaD5e4ga2TGHwL+qIwy8D00JpQQSrD Q0AN7X5GFb77HhYapBslAuhct+6W0LfELPck0vdgWZfP/Q==; 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=PQ1pu1YMBRXV7wv5I0iF9mfGSSAxMaOSHEUhPhRikb4=; b=UrccGBjLH3vsD9KgXHWjjeb0/9 joml3hkmLfk7+8IpXPUERaP1SEYbMRiArBVmEaHWnGcKmex26zB8qF/96V4SLdSu1jeQPNyiB9Coe 7BE985vQfmRU1y+/GkmvBaWqfuHlaYrIhebR3sHaEkb24exqGQ2agRayMtGl+9CYU9bWaTERpeUK5 XDKRSu7MJE3JbMJtFxMIOi/DIxkwZFLb7vejQMwlo2pBhpgxGRg62Au7BaQCoFIhrrb3OVR3mXonG yeLW+EWD7QYGtqkk0IeYMnvSzCwTGCyp7tsrtqCnNVXsXVk/vlCyzEPkiitrvpgjPuSxUAXOjgW86 iHh5TJkw==; Received: by zero.zsh.org with local id 1ow6GJ-000J5x-8c; Fri, 18 Nov 2022 18:38:51 +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]:52154) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1ow6Fy-000Il9-3S; Fri, 18 Nov 2022 18:38:31 +0000 Received: from iris.zentaur.org (localhost [127.0.0.1]) by iris.zentaur.org (Postfix) with ESMTP id 4NDQXP0vQqz3wZj for ; Fri, 18 Nov 2022 18:38:29 +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=1668796708; x=1668800309; bh=JTsE006eumsVGJTG7oKBgxN+UzQqXUdY vckOv3aTJ9M=; b=e9m5Ur6F+Z3iQVVlan+wUmMj37EiPCiQzMD6cO6LZQFX758O Soqg8parYh/8RMJUXBxBLZBGiSh8FZCDtc/3fN9OtcT4jSnAIbq9yPyiOYsPL6s7 2kuW8Pt4Ato/s8FyPlBfRuRt7nBEIq1nXOfCEq3+ttKraowN9QY96OTbs1SWUPH9 fJkGsl314vYA0HJTlKH/3oW8Xb5W8v61d7aLbv2YpV11Onct4xo828F1WLMUPg4b emkA6vemJAkh5KvWtnP9ILeAjd3haIk49vCBnLxzvDT2N79pNjKPvOfLw+lFXj7Y n8DkehBzwDgb2kgxZEHtZ1ZO8VZBKnCBqDDOGA== 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 2oo9DyuOV9HU for ; Fri, 18 Nov 2022 18:38:28 +0000 (UTC) Received: from [10.251.9.101] (rrcs-24-173-95-34.sw.biz.rr.com [24.173.95.34]) by iris.zentaur.org (Postfix) with ESMTPSA id 4NDQXN2kQKz3wZb for ; Fri, 18 Nov 2022 18:38:28 +0000 (UTC) Message-ID: Date: Fri, 18 Nov 2022 12:38:26 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 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> <20221118162325.7i3qzqljyx4a7z3h@chazelas.org> <20221118181253.cdejvepmnsmia7jm@chazelas.org> From: Clinton Bunch In-Reply-To: <20221118181253.cdejvepmnsmia7jm@chazelas.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Seq: 50998 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/18/2022 12:12 PM, Stephane Chazelas wrote: > 2022-11-18 11:08:42 -0600, Clinton Bunch: > [...] >>> Some comments about the API: >>> >>>> -c COUNT >>>> Sets the number of returned random data. Defaults to 8, >>>> unless -i, -L, or -U is specified without -a, in which case >>>> the default is 1. COUNT must be between 1 and 64. >>> Why those arbitrary limits? Why not from 0 to inf? >> the getrandom function only guarantees 256 bytes.=C2=A0 64 32-bit inte= gers. >> Allowing 256 uint8 would be possible, but harder to explain and doesn'= t work >> well with bounding.=C2=A0 As the difference between the lower and uppe= r limit >> surpasses half the max, the number of bytes thrown away to allow unifo= rmity >> of distribution becomes unwieldy. >> >> Also zero would not be particularly useful :) > You could call getrandom() as many times as necessary. From a > user point of view (mine at least) that limit doesn't make > sense. Users don't care what API you use underneath. > > An array can have from 0 to inf elements, a string 0 to inf > bytes, I should be able to request from 0 to inf numbers/bytes to > store in my array/string. I can't do inf (there is a limit to how big an array can be, the largest=20 integer for an index).=C2=A0 I honestly think it's unlikely anyone will n= eed=20 more than 64 random integers.=C2=A0 I saw no reason to expand the limit, = but=20 it can be done. >>> Without -i you get uint8 in hex and with -i uint32 in decimal. >>> Why the different bases? >> It's possible to break a hex string into bytes in a rather straight fo= rward >> way.=C2=A0=C2=A0 A string of decimal numbers not so much, but decimal = numbers are >> easier to manipulate. >> >> If I didn't think it should do *something* when given no arguments, I'= d >> eliminate the hex string altogether. > Alternatively, you could add a -f %02x, -f %u -f %c and do > without the -r/-i, with default -c 8 -f %02x -L 0 -U 255. That seems a lot more confusing than -r (raw) or -i (integer) unless=20 it's expanded to a lot more arbitrary formats.=C2=A0 At least for someone= not=20 familiar with printf formats. > > Or maybe keep the -i but only as an alias for -c 1 -f %u -L 0 -U > $((2**32-1)). (-r would be -f %c) > > [...] >>> Trying to use it to get a random word with it, I came up with: >>> >>> $ set -o extendedglob >>> $ l=3D({A..Z} {a..z} {0..9} _) >>> $ getrandom -a a -c20 -L1 -U$#l >>> $ echo ${(j[])a//(#m)*/$l[MATCH]} >>> EMhKvFuQlmCVSuet5uh0 >>> >>> Doing it straight by reading /dev/urandom would have been a lot >>> more awkward. Could that be improved/simplified? >> It could be done, but a list of acceptable characters would need to be >> agreed upon and documented.=C2=A0 Are symbols acceptable?=C2=A0 About = half of >> passwords require them, but only accept certain ones and that differs = from >> website to website. > [...] > > I was not suggesting you to add that as an extra feature to > getrandom. >