help with randomize name pick batch

Hewlett-packard Ms office 2003 pro
April 14, 2011 at 18:29:49
Specs: Windows XP, 1024
I already have a list of name, I want the batch script will randomly pick a name.

1. john
2. amy
3. sam

output random name: xxxxxx

2nd step, I want to do loop. I want all the name being pick.

output random name 1: amy
output random name 2: sam
output random name 3: John

See More: help with randomize name pick batch

Report •

April 14, 2011 at 18:57:33
You could use something like this:

To randomize the whole file then just run for /f over the temp file.

Report •

April 14, 2011 at 19:54:51
Can you tell me if any of the below is true for your text file:

Do any lines begin with the character "]"?.

Does the the file contain exclamation marks("!")?

Are there any blank lines in the file? And if so do you want to keep them?

Report •

April 14, 2011 at 20:21:20
oh I never have a text file, but a list of name, about 100. Does not have to be in text file, but I want them randomly chosen until all the name gone.

Report •

Related Solutions

April 14, 2011 at 20:27:20
the link is good, and I test it. It is what I looking for.
what happen if I want the name to be a string? are there anyway to add?

for example,
xxxxx is the #1 winner.
xxxxx is the #2 winner.

Report •

April 14, 2011 at 20:27:45
Where is the list coming from then?

Report •

April 14, 2011 at 20:29:02
@echo off
SetLocal EnableDelayedExpansion
set cnt=0
for /f "delims=" %%a in ('shuffle.bat') do (
    set /a cnt+=1
    echo %%a is the #!cnt! winner.

Report •

April 14, 2011 at 20:43:08
the list is hand written.
in ur batch, I have to work with shuffle.bat?

Report •

April 14, 2011 at 20:45:58
Thank you very much.

It is working. Now i have 2 batch.....

Report •

April 14, 2011 at 21:25:54
You don't have to have two, I just didn't really want to
edit the shuffle script, here it is a single script:

SET TmpFile=tmp%RANDOM%%RANDOM%.tmp
TYPE NUL >%Tmpfile%
set cnt=0
FOR /F "tokens=*" %%i IN ('MORE') DO SET Key=!RANDOM!!RANDOM!!RANDOM!000000000000& ECHO !Key:~0,15!%%i>> %TmpFile%
FOR /F "tokens=*" %%i IN ('TYPE %TmpFile% ^| SORT') DO (
    set /a cnt+=1
    SET Line=%%i
    echo !Line:~15! is the #!cnt! winner.
DEL %TmpFile%

Report •

April 15, 2011 at 08:56:02
You can use a random number generator and associate a name with each number like below:

@echo off
set num=%random%
if /i %num% GTR 3 goto pick
if /i %num% LSS 1 goto pick
goto name

if %num% == 1 set name=John
if %num% == 2 set name=Amy
if %num% == 3 set name=Sam
goto finish

echo %name%
pause >nul

The only problem with the one above is that it can take a long time.

Report •

Ask Question