in reply to generating random filenames

As has been pointed out there are better ways of generating a random/temporary file name that is both unique and guaranteed to stay that way as you have an exclusive lock on the file.

It is good practice when generating random numbers to seed the random number generator first using srand. This works pretty well and carries the Camel seal of approval.

srand(time()^($$+($$<<15))); # now do something really random
cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: generating random filenames
by particle (Vicar) on Jul 10, 2001 at 22:24 UTC
    i was under the impression that this wasn't necessary anymore, and looking at srand,
    In fact, it's usually not necessary to call srand() at all, because if + it is not called explicitly, it is called implicitly at the first use of the + rand() operator. However, this was not the case in version of Perl before 5.0 +04, so if your script will run under older Perl versions, it should call sran +d()

    ~Particle

      While I could hide behind a "you need to do this for older versions of perl" the truth is I did not know you can now drop it :-) Thanks for the info. Getting slack on reading those man pages. I'll still probably use it for a while yet though just to make sure my random stuff is random across the board. 5.04 was a while ago now but some systems still use 4!

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print