Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
A strange function behaviour in random password generator
- X-seq: zsh-users 15610
- From: nix@xxxxxxxxxxxxxxxx
- To: zsh-users@xxxxxxx
- Subject: A strange function behaviour in random password generator
- Date: Mon, 6 Dec 2010 15:15:58 +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 have just coded a random password generator. It works good but one
might want to show me how to do it with rand48() as it´s output is
strange.
The problem:
./random_pass.sh
iNkiuG
iNkiuG6K
6 first chars are the same for both passwords.
The question:
How to fix the above problem without redefining the same function inside a
loop and calling it again?
[CODE]
#!/bin/zsh
zmodload zsh/terminfo
emulate zsh
function random () {
local length=$1
[ -z "$length" ] && { echo "Error: lenght" ; exit 0 }
if [[ $length != <-> ]] ; then
echo "Error: lenght is non-numeric" ; exit 0
fi
seeds="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
seeds_count="${#seeds}"
z="0"
local password=""
local variable=inside
until [ $z -eq $length ] ; do
pos=$((RANDOM%$seeds_count+1))
password+=$(echo $seeds[$pos])
let "z++"
done
echo -n $password
}
MY_RCON=$(random 6)
echo $MY_RCON
MY_PASS=$(random 8)
echo $MY_PASS
Messages sorted by:
Reverse Date,
Date,
Thread,
Author