I need a batch file that generates a random 5 of the following:

x, xx, xxx, xxxx, xxxxx, xxxxxx, xxxxxxx, xxxxxxxx, xxxxxxxxx

If possible i would rather the ones with fewer x's to have a higher chance of being chosen.An example outcome could be: xxx xxxxx xx xx x

No clue how to weigh the results towards smaller values (I flunked statistics 101).

Here's a stab at a possible attempt at an approach to a solution that won't work:

::===== begin batchscript

@echo off & setlocal enabledelayedexpansion

set x=xxxxxxxxx

set u=

:0

for /L %%j in (1,1,5) do (

for /L %%i in (1,1,9) do (

set a=%%i

if %%i equ 9 set a=5

if %%i equ 1 set a=9

if %%i equ 4 set a=7

)

call :xx

)

goto :display

:xx

set /a z=%random%"%%"a

set /a z+=1

set t=!x:~0,%z%!

set u=%u% %t%

goto :eof:display

echo %u%

Thanks! Works perfectly.

Ask Your Question

Weekly Poll