From: John Kelly on

Interix has no "mktemp -d" utility.

I could loop a "mkdir /tmp/$RANDOM" until I find a directory name not
already taken, but I'd rather have some alpha characters in the string,
like "mktemp -d" produces.

So I thought of reading a few characters from /dev/urandom to get what I
want. But I wonder, is /dev/urandom available on most platforms?

Or perhaps take a value from $RANDOM and use it as a seed to a string
randomizing function. Anybody already written something like that?



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: Randal L. Schwartz on
>>>>> "Michael" == Michael Vilain <vilain(a)NOspamcop.net> writes:

Michael> Why not make a directory with the hex representation of the UNIX
Michael> localtime? That should never be the same. No looping
Michael> required.

Unless it's twice within the same second. Ouch.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn(a)stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
From: Randal L. Schwartz on
>>>>> "John" == John Kelly <jak(a)isp2dial.com> writes:

John> Or perhaps take a value from $RANDOM and use it as a seed to a string
John> randomizing function. Anybody already written something like
John> that?

maybe:

z=/tmp/`openssl rand -hex 32`

That burns 256 bits of randomness, without making the filename too long.

And if you don't have openssl, you *should*. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn(a)stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
From: John Kelly on
On Tue, 10 Aug 2010 20:08:32 -0700, merlyn(a)stonehenge.com (Randal L.
Schwartz) wrote:

>>>>>> "John" == John Kelly <jak(a)isp2dial.com> writes:
>
>John> Or perhaps take a value from $RANDOM and use it as a seed to a string
>John> randomizing function. Anybody already written something like
>John> that?
>
>maybe:
>
> z=/tmp/`openssl rand -hex 32`
>
>That burns 256 bits of randomness, without making the filename too long.
>
>And if you don't have openssl, you *should*. :)

I could even get by with 4

# /usr/local/ssl/bin/openssl rand -hex 4
de04a9ce

But I'm not sure I want to rely on an external utility. I'd rather do
it all in shell code. I could spend some time and write a shell RNG but
I was wondering if anyone has already implemented that wheel.

It doesn't have to be FIPS strong. It just needs to be good enough to
avoid short cycles and find an unused directory name, without excessive
retries.



--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php

From: John Kelly on
On Tue, 10 Aug 2010 19:41:38 -0700, Michael Vilain
<vilain(a)NOspamcop.net> wrote:

>In article <c0p366du2oku06uo4ssiun5gn2ljovv5gn(a)4ax.com>,
> John Kelly <jak(a)isp2dial.com> wrote:
>
>> Interix has no "mktemp -d" utility.
>>
>> I could loop a "mkdir /tmp/$RANDOM" until I find a directory name not
>> already taken, but I'd rather have some alpha characters in the string,
>> like "mktemp -d" produces.
>>
>> So I thought of reading a few characters from /dev/urandom to get what I
>> want. But I wonder, is /dev/urandom available on most platforms?
>>
>> Or perhaps take a value from $RANDOM and use it as a seed to a string
>> randomizing function. Anybody already written something like that?
>
>Why not make a directory with the hex representation of the UNIX
>localtime? That should never be the same. No looping required.

GNU date is good with the nanoseconds format:

# date +%N
795401515

# date +%N
387506541

But Interix date has no such format specifier:

# date +%N
N

Alas, portability.


--
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php