Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
A few rand48() example for the list
- X-seq: zsh-users 15869
- From: nix@xxxxxxxxxxxxxxxx
- To: zsh-users@xxxxxxx
- Subject: A few rand48() example for the list
- Date: Sat, 12 Mar 2011 00:42:32 +0200
- Importance: Normal
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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