Re: random filenames
- Posted by jacques deschĂȘnes <desja at globetrotter.net> Mar 19, 2007
- 521 views
Hi Hayden, the reason for unprintable character is that rand(125)+1 generate values between 1 and 126 and codes below 32 are unprintable replace rand(125)+1 by rand(93) + 32 but beware that some characters like '\' are forbidden in windows filenames so a better choice could be rand(26)+'a' (limit to lower case letters) But all this is not 100% collision proof. regards, Jacques D. Hayden McKay wrote: > > Doe's anyone know how to implement a small runtime cross-platform random > filename > generator? > > I'm currently just adding the '~' char to the filename > ie: filename = '~' & filename > > I've written a small template but it will return unprintable chars; > > }}} <eucode> > function TempFile(sequence mode) > sequence s > > s = repeat(-1, 8) > for j = 1 to 8 do -- DOS filename compatablity > s[j] = rand(125 + 1) > end for > > s &= ".TMP" > > return OpenFile(s, mode) > > end function > </eucode> {{{ > > Maybee a 'set_rand()' might fix?