David Douthitt wrote:
> 
> Matt Schalit wrote:
> >
> > I'm trying to generate a random number between 10,000 and 60,000.
> > I've figured that with Oxygen and Dachstein I can gather random
> > bytes using dd:
> >
> >   dd if=/dev/random of=/tmp/rbytes bs=1 count=1
> >
> > So the file /tmp/rbytes has a string of 4 random characters.
> 
> I tried this, and I got one byte (bs=1 count=1).


Oops, I typed that wrong.  I meant count=4.

 
> > Um, how do I covert those from ascii to integer?  I tried printf.
> 
> Only thing I could find was od - and that's not in any standard 
> LEAF I know of.  Might be among the Oxygen developer packages or 
> in the package list, but it seems likely to be overkill for what 
> you want.

No od, no bc, no tr, no typeset.  The usual tricks
I've heard about aren't there.

 
> Turns out bash has the RANDOM variable which does what you want - 
> but my version of ash (on my workstation) doesn't have it.
 

I'm definitely trying to do this on any default LEAF
distro.  That means trying to use out of the box commands
so that the user is not asked to install other packages.


> Then I found the "openssl rand" command.
> 
> Sigh - random numbers everywhere except anywhere helpful :-(

Back to "where's openssl," huh?  That's funny.

Well, here's the trick I've been using so far, but 
it only works on Oxygen, because Dachstein doesn't
come with md5sum by default:

       until [ "$RANDOM" -ge 10000 -a "$RANDOM" -le 60000 ] ; do
          RANDOM=`( $PS aux && date ) | md5sum | $CUT -c4-8`
          $E ".\c"
       done 2>/dev/null

This works because the md5sum changes with every iteration.
It has always taken less than 100 iterations to come up with
a section of the sum (characters 4 - 8) that are all numbers
and are all within the range.  Nifty, huh?  Problem is that
there's no md5sum in Dachstein.

Why no md5sum in Dachstein?  Doesn't it check it's packages?
Thanks,
Matthew

_______________________________________________
Leaf-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-devel

Reply via email to