Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

A few rand48() example for the list



Hi. I remember asking earlier for rand48() related but could not get a
working solution. Afterwards I found it on my own.

Here are a few handy solutions.

Random password using rand48():

zmodload -i zsh/mathfunc

length=8 # Max possible value are equal to size of $chars.
chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?:^~@#$%&*_+=[]/"

while (( i++ < length ))
do
        random=$((1 + int(${(c)#chars} * rand48())))
        password+="$chars[$random]"
        chars[$random]=""
done

print "$password"

Random word from a string using rand48():

zmodload -i zsh/mathfunc

words="NIX Linux ZSH BASH PHP"

word=$((1 + int(${(w)#words} * rand48())))
print ${${words[*]}[(w)$word]}

---
The ran48()is significantly more random than bash/zsh $RANDOM built-in

Regards NiX




Messages sorted by: Reverse Date, Date, Thread, Author