China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 15:41
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Bonus question for beginners - random value taking View 2,072 Replies 24
Original Poster Posted 2008-08-24 10:32 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Long time no issue, today I'll make one for newcomers, and veterans please skip:

Title:
Now there is a one-to-one correspondence between a-z and 1-26. Now we need to use batch processing to randomly get 10 different values from 52 values of 1-26 and a-z (all regarded as values). For example, 1 and a, 26 and z are regarded as the same value.

Requirements:
The code is efficient, concise, general, and does not generate temporary files.

Bonus:
Add 10 points if the code fully meets the requirements.
批处理之家新域名:www.bathome.net
Floor 2 Posted 2008-08-24 14:29 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
It seems that now there are more people asking for code, and really few who come with the purpose of learning. Alas...
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-08-24 14:58 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
Sigh.. Not much popularity..
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 4 Posted 2008-08-24 15:31 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 209
Posts 100
Joined 2008-08-01 02:53
18-year member
UID 122532
Gender Male
Status Offline
The difficulty is too great, I don't understand enough. Can't take it. I'm not here for the code.
Floor 5 Posted 2008-08-24 15:33 ·  中国 江苏 苏州 电信
中级用户
★★
Credits 209
Posts 100
Joined 2008-08-01 02:53
18-year member
UID 122532
Gender Male
Status Offline
I am dull-witted, sincerely seeking to become an apprentice. Those who like to take apprentices come!
Floor 6 Posted 2008-08-24 16:26 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
It's really hard to make a decision... Although I really want to move it up, but am I considered an old hand?
Floor 7 Posted 2008-08-24 16:46 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
I'll add another water post, hey, there's no way. Some people are all transitioning to bathome.
Floor 8 Posted 2008-08-24 17:54 ·  中国 广东 深圳 电信
初级用户
Credits 53
Posts 27
Joined 2005-07-18 20:40
21-year member
UID 40849
Status Offline
It feels quite difficult... Alas. Continue my snail - like learning journey.
Floor 9 Posted 2008-08-24 19:18 ·  中国 江苏 常州 电信
初级用户
Credits 26
Posts 13
Joined 2006-09-24 22:38
19-year member
UID 63566
Status Offline
DOS is blind. It's difficult. Take your time.
Floor 10 Posted 2008-08-24 19:29 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Tips: Focus more on the correspondence one by one
批处理之家新域名:www.bathome.net
Floor 11 Posted 2008-08-24 22:52 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
Oh, I'm dizzy, didn't expect it to be so difficult...

[ Last edited by BC on 2008-8-25 at 08:32 AM ]
Floor 12 Posted 2008-08-24 23:51 ·  中国 陕西 西安 电信
初级用户
Credits 34
Posts 17
Joined 2007-05-23 10:55
19-year member
UID 89042
Gender Male
Status Offline
@echo off
setlocal EnableDelayedExpansion
set nu=a b c d e f g h i j k l m n o p q r s t u v w x y z
set n=0
:_loop
if %n% geq 10 (goto _end)
set /a n=%n%+1
set /a unx=%random%%%26+1
for /f "tokens=%unx% delims= " %%i in ('echo %nu%')do echo %n% %%i %unx%
goto _loop
:_end

Is this the case???
Or set nu= a-z + 1-26
set unx=%random%%%52+1 ????

[ Last edited by daker on 2008-8-25 at 12:06 AM ]
Floor 13 Posted 2008-08-25 01:21 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
The LZ means that if 3 has already appeared, then 3 cannot appear again, and c cannot appear. a-1, b-2, c-3... are all in one - to - one correspondence.
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 14 Posted 2008-08-25 08:53 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
@echo off
setlocal enabledelayedexpansion
set num=1234567890
set wor=abcdefghijklmnopqrstuvwxyz
:a1
set /a var1=%random%%%26+1
set /a var2=%random%%%9+1
if %var1% equ %var2% (goto :a1)
if %var1% lss 1 ( goto :a1 )
set key1=!wor:~%var1%,9!
set key2=!num:~%var2%,1!
echo %key1%%key2%
pause
Got a very lazy method, and it's not very in line with the topic, but my ability is just that much...
Hope some experts can give guidance...
Floor 15 Posted 2008-08-25 10:15 ·  中国 四川 成都 电信
新手上路
新手上路
Credits 6
Posts 3
Joined 2008-08-21 22:15
17-year member
UID 123813
Gender Male
From 川
Status Offline
```batch
@echo off
Setlocal Enabledelayedexpansion
set _w=0abcdefghijklmnopqrstuvwxyz
set _p=0
for /l %%i in (1 1 26) do (set w%%i=!_w:~%%i,1!
set _w%%i=%%i)
:xz
set /a _p+=1
if %_p%==11 goto show
set /a xzx=%random%%%2
set /a xzp=%random%%%26+1
if %xzx%==0 set show%_p%=%xzp%
if %xzx%==1 set show%_p%=!w%xzp%!
goto xz
:show
for /l %%i in (1,1,10) do set /p =!show%%i! <nul
pause>nul
但不能判断是否重复....
望前辈指教
```
Forum Jump: