#! /bin/zsh # # By Peter Stephenson @ gmane.comp.shells.zsh.user: # # Generate a 48-bit pseudo-random number as # a floating point value between 0 and 1 in $REPLY. # # This version is slow but works around the fact that # the random number seed doesn't propagate back from # a subshell by storing the seed in a file. # # You can specify a file name, else # ${ZDOTDIR:-~}/.zsh-rand48-seed is used, but if # using the default be careful about simultaneous # accesses from multiple shells." zmodload zsh/mathfunc rand48 () { local file=${1:-${ZDOTDIR:-~}/.zsh-rand48-seed} local seed [[ -f $file ]] && seed=$(< $file) typeset -g REPLY=$(( rand48(seed) )) print $seed > $file echo $seed } alias random-string=rand48