Batch file random alpha-num codes

Lenmar Lenmar replacement battery for hp...
June 11, 2010 at 10:57:57
Specs: Windows Vista
i need some help in solving how to create a Keygen
that can spits out codes that look like this
it must be in CMD though


it must be somewhat random

here is the rough source code that i'm using at the

@echo off
setlocal EnableDelayedExpansion
set times=0
set r=%random:~-1%
if !r! GTR 5 goto loop
if !r! LSS 1 goto loop
set /a times+=1
set /a rnd!times!=!r!
if !times! LSS 5 goto loop
echo !List:~%rnd1%,1!%rnd1%!List:~%rnd2%,1!%r…
echo !List:~%rnd1%,1!%rnd1%!List:~%rnd2%,1!%r…
goto again

See More: Batch file random alpha-num codes

Report •

June 11, 2010 at 15:48:37
@echo off & setLocal EnableDELAYedeXpansion

set S=abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
set N=10
set C=

for /L %%a in (1 1 !N!) do (
  set /a P=!random!%%62
  call :sub1 !P!

goto :eof

  set C=!C!!S:~%1,1!
goto :eof

Helping others achieve escape felicity


Report •

June 11, 2010 at 16:08:23
thanks alot that worked :) just had to add a pause button to it
because the cmd batch would suddenly disappear.

Report •

June 11, 2010 at 16:16:20
I know I'm late, just posting because I already wrote it ;).

Much the same as M2's(Hi M2!) script but with semi variable string length. I only bothered with lower case, but that's easily changed:

@echo off
SetLocal EnableDelayedExpansion

::Both maxlen and minlen must be at least 1
::Minlen must be less than or equal to maxlen
::lenset == number of chars in charset
set maxlen=15
set minlen=5
set charset=0123456789abcdefghijklmnopqrstuvwxyz
set lenset=36

set ranstr=
set /a strlen=(%random% %% ((maxlen + 1) - minlen)) + minlen
for /l %%a in (1 1 %strlen%) do (
    set /a char=!random! %% lenset
    for %%b in (!char!) do set ranstr=!ranstr!!charset:~%%b,1!

echo !ranstr!

Report •

Related Solutions

June 12, 2010 at 02:12:27
thanks i'm beginning to see how you guys programmed these.
is it possible to make a keygen that can make words as well?
because i'm noticing slight patterns in the way the alpha-num
characters are coming out. and i'm not getting full words.
(maybe 3 letter words but that's it)

Report •

June 12, 2010 at 02:15:34
i'm impressed Judago! your module is slightly faster in spitting
out the data. (when looping) than M2's i like it.

Report •

June 12, 2010 at 02:44:01
Depends on what you mean by WORDS.

Helping others achieve escape felicity


Report •

June 12, 2010 at 03:40:38
As M2 said it depends on you definition of word, you could easily bias the string with more vowels(i.e 3 a's, 3 e's, ect) but their is no guarantee you would get words from language, though it would likely yield more pronounceable "words".

If you want words from language it would be a lot easier to grab a plain text dictionary off the net and use a random line/word from it instead.

Nfinch: your module is slightly faster in spitting
out the data. (when looping) than M2's i like it.

That's probably on account of it being only lower case(unless you changed it), but it could be the call causing the hit....

Report •

June 19, 2010 at 18:22:56
nah the lowercase doesn't really make the difference. yeah i
think it was the calling. which makes more sense... and um
where would i go about getting a text dictionary?

Report •

June 19, 2010 at 21:47:54
I should of said word list instead of dictionary(because that is what I was really referring to). A quick search of google for "word list" brings up heaps of results.

For english you can try:

You would probably need to mix files to make a full list because variations(ie British vs Us spelling) are kept separately in the archive(I only tried the first one.).

If you happen to have open office installed you should be able to grab a list from the install instead (hint "dir /s /b installdir\*.dic").

Report •

Ask Question