From: Jon LaBadie on
mop2 wrote:
> On Sun, 31 Jan 2010 15:38:33 -0200, Jon LaBadie <jlabadie(a)axcxm.org> wrote:
>
>> mop2 wrote:
>>> On Sun, 31 Jan 2010 14:33:32 -0200, Brendan <brendandetracey(a)yahoo.com>
>>> wrote:
>>>
>>>> Hello,
>>>>
>>>> An oft-repeated means for seeding bash $RANDOM is:
>>>> RANDOM=$$$(date +%s)
>>>>
>>>> However on Linux 2.6.18-xen #1 SMP Fri May 18 16:11:33 BST 2007 i686
>>>> GNU/Linux thise method is not working for me:
>>>> RANDOM=$$$(date +%s)
>>>> echo $RANDOM
>>>>
>>>> I keep getting a value of 15929. Why is the seed value invalid? 32-bit
>>>> OS?
>>>>
>>>> Thanks
>>>>
>>>>
>>>
>>> RANDOM is a special var.
>>>
>>> Try:
>>> unset RANDOM
>>> RANDOM=$(date +%s)
>>
>> You should have tried it yourself.
>>
>> unsetting RANDOM takes away its "specialness".
>
> Is not this exactly what the OP wants?

unset'ting RANDOM makes it stop giving "random" values.

My understanding of the OP's wants is to reposition within
the random sequence, but still get "random" values.
From: David W. Hodgins on
On Sun, 31 Jan 2010 11:33:32 -0500, Brendan <brendandetracey(a)yahoo.com> wrote:

> An oft-repeated means for seeding bash $RANDOM is:
> RANDOM=$$$(date +%s)

Where have you seen that? $RANDOM returns a number from
0 to 32767. date +%s returns the number of seconds sinc
1970-01-01 00:00:00 UTC, which currently is 1264963457.

The above is setting the seed to the process id concatenated
with the seconds since 1970.

Currently on my system $$$(date +%s) is returning
185421264964247, which is not a valid seed. The seed should
be from 0 to 32767.

It isn't clear what RANDOM does with an invalid seed, but it's
clearly assuming some fixed value. Try ...

seed=$$$(date +%s)
let "seed %= 32766"
RANDOM=$seed

This is a slight modification of what's used in Example 34-4 from
http://tldp.org/LDP/abs/html/bashver2.html
which only uses date +%s rather then including the process id.

Regards, Dave Hodgins

--
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)
From: Brendan on
On Jan 31, 3:11 pm, "David W. Hodgins" <dwhodg...(a)nomail.afraid.org>
wrote:
> On Sun, 31 Jan 2010 11:33:32 -0500, Brendan <brendandetra...(a)yahoo.com> wrote:
> > An oft-repeated means for seeding bash $RANDOM is:
> > RANDOM=$$$(date +%s)
>
> Where have you seen that?  $RANDOM returns a number from
> 0 to 32767.  date +%s returns the number of seconds sinc
> 1970-01-01 00:00:00 UTC, which currently is 1264963457.
>
> The above is setting the seed to the process id concatenated
> with the seconds since 1970.
>
> Currently on my system $$$(date +%s) is returning
> 185421264964247, which is not a valid seed.  The seed should
> be from 0 to 32767.
>
> It isn't clear what RANDOM does with an invalid seed, but it's
> clearly assuming some fixed value.  Try ...
>
> seed=$$$(date +%s)
> let "seed %= 32766"
> RANDOM=$seed
>
> This is a slight modification of what's used in Example 34-4 fromhttp://tldp.org/LDP/abs/html/bashver2.html
> which only uses date +%s rather then including the process id.
>
> Regards, Dave Hodgins
>
> --
> Change nomail.afraid.org to ody.ca to reply by email.
> (nomail.afraid.org has been set up specifically for
> use in usenet. Feel free to use it yourself.)

Thanks Dave. It is funny, because the seeding method I used is all
over the internet, but is obviously wrong["What?! You mean the
interweb can't be trusted?!!!"]. I will forego setting the seed myself
and let the default take care of it i.e. $RANDOM is auto-seeded by the
PID.