zsh-users
 help / color / mirror / code / Atom feed
* A few rand48() example for the list
@ 2011-03-11 22:42 nix
  0 siblings, 0 replies; only message in thread
From: nix @ 2011-03-11 22:42 UTC (permalink / raw)
  To: zsh-users

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-11 22:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-11 22:42 A few rand48() example for the list nix

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).