Subject: Re: Re: [ksh93-integration-discuss] Toy patch: Let ${RANDOM} use
/dev/urandom
--------
Henk Langeveld wrote:
>
> James Carlson wrote:
> > I don't think there's really a good option available with just one
> > mechanism.
> >
> > If you make $RANDOM "really random" by default, but revert to normal
> > seeded rand() mode when written to, then users will be confused. On
> > some platforms, reading from $RANDOM alone (without initializing) will
> > produce high quality random numbers. On other platforms, it'll
> > produce the worst-possible randomness. If smart users try to make
> > their applications robust by writing $$ (or some such) to $RANDOM,
> > they'll perversely end up with lower quality randomness by accident on
> > platforms that have /dev/urandom (which isn't just Solaris, but may
> > not be all platforms).
> >
> > I think it'd be better to keep the default $RANDOM behavior, and
> > create a new $URANDOM defined to return higher-quality randomness
> > without initialization.
>
> I second that.
>
> And though James has summarised well, I'd like to stress that the use
> of ${RANDOM} has a documented interface - the fact that you can assign
> a seed to it implies a pseudo-random series.
>
> I also support Roland's proposal, but there should be a separate interface.
>
> "Change an interface, change the name" is the holy writ in Solaris.
>
> (and should be in all systems development)
>
> Cheers,
> Henk
>
The current RANDOM model is highly portable and can allow for
repeatable sequences which is useful for testing purposes.
/dev/urandom does not exist on all systems.
However, with discipline functions, RANDOM can be extended
to support /dev/urandom. For example, with the following
discipline functions, an application would be able to say
RANDOM=/dev/urandom
and then $RANDOM will provide 32 bit random numbers as
produced by /dev/urandom.
====================cut here===========================
RANDOM.set()
{
[[ ${RANDOM.pid} ]] && kill ${RANDOM.pid} 2> /dev/null
unset RANDOM.pid
if [[ ${.sh.value} == /* && -r ${.sh.value} ]]
then od -An -w1 -tx4 < ${.sh.value} |&
RANDOM.pid=$!
exec {RANDOM.fd}<& p
.sh.value=0
fi
}
RANDOM.unset()
{
[[ ${RANDOM.pid} ]] && kill ${RANDOM.pid} 2> /dev/null
unset RANDOM.pid
}
RANDOM.get()
{
if [[ ${RANDOM.fd} ]] && read -u ${RANDOM.fd}
then (( .sh.value = 16#$REPLY))
fi
}
====================cut here===========================
David Korn
dgk at research.att.com