Jump to content

Random letter/number generation


Recommended Posts

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%.default
mkdir "%appdata%\Mozilla\firefox\Profiles\%profile%\"
xcopy "%systemdrive%\install\fxprofile\*" "%appdata%\mozilla\firefox\profiles\%profile%\" /Q /Y
echo F | xcopy "%systmedrive%\install\profiles.ini" "%appdata%\mozilla\firefox\profiles.ini" /Q /Y
echo Path=Profiles/%profile% >> "%appdata%\mozilla\firefox\profiles.ini"

This is on Windows 2000 Professional. Thanks - any help would be greatly appreciated. :)

Edited by Idontwantspam
Link to comment
Share on other sites


Try something like this, (untested):

@Echo off&Setlocal enableextensions
:_b
Set "s_="&Set "c_=0"&Set "x_=abcdefghijklmnopqrstuvwxyz1234567890"
:_l
Set/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 _b
Set "r_=%a_%\Profiles\%p_%"
Xcopy "%SystemDrive%\install\fxprofile\*" "%r_%" /s/c/i/q>Nul
Copy "%SystemDrive%\install\profiles.ini" "%a_%"
>>"%a_%\profiles.ini" Echo:Path=Profiles/%p_%

Hope it helps

Link to comment
Share on other sites

Seeing that Yzöwl :thumbup 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.txt

And another one inside this seemingly unrelated batch salt.cmd:

:sneaky:http://www.boot-land.net/forums/?showtopic=2984&st=28

This 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.htm

You 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.php

you 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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...