zsh-users
 help / color / mirror / code / Atom feed
From: nix@myproxylists.com
To: zsh-users@zsh.org
Subject: A few rand48() example for the list
Date: Sat, 12 Mar 2011 00:42:32 +0200	[thread overview]
Message-ID: <c10f7b3c6d90d06d50d47fb563740acd.squirrel@gameframe.net> (raw)

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



                 reply	other threads:[~2011-03-11 22:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c10f7b3c6d90d06d50d47fb563740acd.squirrel@gameframe.net \
    --to=nix@myproxylists.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).