computing
  • 7

Help With Randomize Name Pick Batch

  • 7

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

Share

1 Answer

  1. You don’t have to have two, I just didn’t really want to
    edit the shuffle script, here it is a single script:

    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    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%
    ENDLOCAL
    pause
    

    • 0