Idontwantspam Posted May 11, 2008 Share Posted May 11, 2008 (edited) I need to generate a random, 8-digit combination of numbers and lowercase letters, for the purposes of creating the firefox profile folder, which is named xxxxxxxx.default. I tried using %random% but it seems to be a different length every time I use it, and it doesn't use letters. Is there any other command-line tool I can use to get 8 random letters/numbers? Here's my code right now: set profile=%random%.defaultmkdir "%appdata%\Mozilla\firefox\Profiles\%profile%\"xcopy "%systemdrive%\install\fxprofile\*" "%appdata%\mozilla\firefox\profiles\%profile%\" /Q /Yecho F | xcopy "%systmedrive%\install\profiles.ini" "%appdata%\mozilla\firefox\profiles.ini" /Q /Yecho Path=Profiles/%profile% >> "%appdata%\mozilla\firefox\profiles.ini"This is on Windows 2000 Professional. Thanks - any help would be greatly appreciated. Edited May 11, 2008 by Idontwantspam Link to comment Share on other sites More sharing options...
Yzöwl Posted May 12, 2008 Share Posted May 12, 2008 Try something like this, (untested):@Echo off&Setlocal enableextensions:_bSet "s_="&Set "c_=0"&Set "x_=abcdefghijklmnopqrstuvwxyz1234567890":_lSet/a "n_=%random% %% 36"Call Set "s_=%s_%%%x_:~%n_%,1%%"Set/a "c_+=1"If %c_% Neq 8 Goto _l:Set p_=%s_%.default&Set "a_=%AppData%\Mozilla\Firefox"If Exist "%a_%\Profiles\%p_%" Goto _bSet "r_=%a_%\Profiles\%p_%"Xcopy "%SystemDrive%\install\fxprofile\*" "%r_%" /s/c/i/q>NulCopy "%SystemDrive%\install\profiles.ini" "%a_%">>"%a_%\profiles.ini" Echo:Path=Profiles/%p_%Hope it helps Link to comment Share on other sites More sharing options...
jaclaz Posted May 12, 2008 Share Posted May 12, 2008 Seeing that Yzöwl already replied I should shut up, but maybe you can find in my post some further ideas/explanations.%random% generates a pseudo-random number between 0 and 32767.You need to "parse" the output to somehow generate a fixed number of characters.An example is here:http://www.robvanderwoude.com/files/random_nt2.txtAnd another one inside this seemingly unrelated batch salt.cmd: :sneaky:http://www.boot-land.net/forums/?showtopic=2984&st=28This is limited to numbers, you could use a substitution routine with a subset of characters, like a÷z and A÷Z. A good example of such a routine can be found here:http://www.fpschultze.de/smartfaq+faq.faqid+262.htmYou will need to use numbers in the range 10÷99 and use two characters instead of one, with a list in the FOR loop like 10A 11B 12C, etc., with Call :Exec Set s=%%s:%_:~0,2%=%_:~2,1%%%leaving the numbers 0÷9 "pass through".The alternative is using an external .exe to generate the pseudo-random alphanumeric string, any of the freeware MD5 generators would do, like this one:http://www.diamondcs.com.au/consoletools/md5.phpyou just run it against some machine specific file, than extract from it the needed amount of characters.jaclaz Link to comment Share on other sites More sharing options...
xdb0wx Posted May 16, 2008 Share Posted May 16, 2008 I bought this book called "Sams' teach yourself C in 24 hours" and I can't find the page but i think it says something like %random% (x=o y>x y=10) [you can make "y=10" to 'y=8' for the 8 numbers]I am most likely wrong but I'll try to find the page. Link to comment Share on other sites More sharing options...
IcemanND Posted May 16, 2008 Share Posted May 16, 2008 Why make it a random name? Why not make life easy on yourself and create the profile and folder using the logged on user name? There is no reason why the folder name needs to be random, at least not as far as Firefox is concerned. Mine is in the my documents folder and is my login id. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now