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

A strange function behaviour in random password generator



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