Robert Connolly wrote: > I need help understanding the Bash manual page: > > RANDOM Each time this parameter is referenced, a random integer between > 0 and 32767 is generated. The sequence of random numbers may be > initialized by assigning a value to RANDOM. If RANDOM is unset, > it loses its special properties, even if it is subsequently > reset. > > The Korn shell has the same manual page statement, more or less. > > This is the current behavior: > > $ RANDOM=1 > $ echo $RANDOM > 16838 > $ echo $RANDOM && echo $RANDOM > 8312 > 20622 > $ RANDOM=1 > $ echo $RANDOM > 16838 > > I don't understand "If RANDOM is unset, it loses its special properties, > even if it is subsequently reset.". From what I see of the behavior, $RANDOM > is not random if you initialize it yourself, but neither is any pseudo random > number generator. What I'm wondering is whether the "seed" should be saved > only for the session, so that 'RANDOM=1 ; echo $RANDOM' is not the same in > every session... that the old seed is lost forever if RANDOM is > reinitialized. > > It's easy to change Bash to make $RANDOM random whether you initialize it or > not (the initialization would actually be ignored). Is there any practical > use for having 'RANDOM=1 ; echo $RANDOM' the same on every system? If $RANDOM > is going to actually be random, then the manual page needs to be modified to > reflect that. > > robert >
This is really interesting. I tried out the RANDOM thing you mentioned, and played with it a little bit. At least in my case, I got the same first result as you after setting RANDOM to 1. Then I unset it. After I unset it, RANDOM no longer returned random numbers. It just returned the value I set it to. I suppose that's what the man page means when it says it 'loses its special properties.' I'm not sure if you can get it to generating random numbers again after you unset it, but I haven't really did anything too involved to verify this. William Dolorito -- http://linuxfromscratch.org/mailman/listinfo/hlfs-dev FAQ: http://www.linuxfromscratch.org/faq/ Unsubscribe: See the above information page
