On 10/23/2022 11:47 PM, Bart Schaefer wrote:
On Sun, Oct 23, 2022 at 7:57 PM Clinton Bunch <cdb_zsh@xxxxxxxxxxx> wrote:
On 10/23/2022 9:01 PM, Bart Schaefer wrote:I was referring to the spelling of "randome".
* Typo in the introductory comment.I'm pretty sure I've since found and changed all the instances of
Zoltan's name.
... because?Actual question: What's the use case for returning or printing aMostly because I see constructs like read -k6 -u3 3</dev/urandom
block of random bytes? Why does this need to be a builtin?
I did it to seed rand48. Roman did it to generate a 32-bit random integer. Both of which are obsoleted by other parts of this module.
I'm sure there are other reasons someone might want to read more or less than 4 bytes of random data. One that comes to mind is generating a password in a platform-independent way without assuming perl or python.
Here's an example:
randpw () {
local
chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890@#%&()"
local tmp
local -i num
num=${1:-10}
getrandom -l $num -s tmp
for i in {1..${#tmp}..2}
do
print -n
${chars["16#${tmp[$i,$i+1]}"%${#chars}+1]}
done
echo
}
Actually, it does both.
it would be nice to initialize an array with random numbers withoutBut you're not filling an array with random numbers, you're filling a
having to use a loop to access SRANDOM n times.
string (scalar) with random bytes.
Still seems like something you do because you can rather than because it's intuitive to the user. Also, your example assumes you'd only want to do this in a function (or wrap it in an anonymous function just for this purpose)
You make it local so you're not leaving it.Suggestion: Treat SRANDOM like SECONDS, in that you can change theThat would seem confusing to me, and too easy to forget which state you
type from integer to floating-point. Then maybe the zrandom() math
function isn't needed?
left it in.
() {
print $SECONDS;
() {
local -F SECONDS
print $SECONDS
}
print $SECONDS
}
56
0.0000050000
56
zrandom was meant to be a replacement for rand48OK.