![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-09 14:51 |
47,811 topics / 349,896 posts / today 1 new / 48,254 members |
| DOS批处理 & 脚本技术(批处理室) » Bonus question for beginners - random value taking |
| Printable Version 2,066 / 24 |
| Floor1 bat-zw | Posted 2008-08-24 10:32 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
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. |
|
| Floor2 bat-zw | Posted 2008-08-24 14:29 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
It seems that now there are more people asking for code, and really few who come with the purpose of learning. Alas...
|
|
| Floor3 pusofalse | Posted 2008-08-24 14:58 |
| 银牌会员 Posts 646 Credits 1,604 | |
|
Sigh.. Not much popularity..
|
|
| Floor4 dragonamd | Posted 2008-08-24 15:31 |
| 中级用户 Posts 100 Credits 209 | |
|
The difficulty is too great, I don't understand enough. Can't take it. I'm not here for the code.
|
|
| Floor5 dragonamd | Posted 2008-08-24 15:33 |
| 中级用户 Posts 100 Credits 209 | |
|
I am dull-witted, sincerely seeking to become an apprentice. Those who like to take apprentices come!
|
|
| Floor6 523066680 | Posted 2008-08-24 16:26 |
| 银牌会员 Posts 1,133 Credits 2,362 | |
|
It's really hard to make a decision... Although I really want to move it up, but am I considered an old hand?
|
|
| Floor7 523066680 | Posted 2008-08-24 16:46 |
| 银牌会员 Posts 1,133 Credits 2,362 | |
|
I'll add another water post, hey, there's no way. Some people are all transitioning to bathome.
|
|
| Floor8 holee | Posted 2008-08-24 17:54 |
| 初级用户 Posts 27 Credits 53 | |
|
It feels quite difficult... Alas. Continue my snail - like learning journey.
|
|
| Floor9 kghong | Posted 2008-08-24 19:18 |
| 初级用户 Posts 13 Credits 26 | |
|
DOS is blind. It's difficult. Take your time.
|
|
| Floor10 bat-zw | Posted 2008-08-24 19:29 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Tips: Focus more on the correspondence one by one
|
|
| Floor11 BC | Posted 2008-08-24 22:52 |
| 中级用户 Posts 175 Credits 338 | |
|
Oh, I'm dizzy, didn't expect it to be so difficult...
[ Last edited by BC on 2008-8-25 at 08:32 AM ] |
|
| Floor12 daker | Posted 2008-08-24 23:51 |
| 初级用户 Posts 17 Credits 34 | |
|
@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 ] |
|
| Floor13 pusofalse | Posted 2008-08-25 01:21 |
| 银牌会员 Posts 646 Credits 1,604 | |
|
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.
|
|
| Floor14 BC | Posted 2008-08-25 08:53 |
| 中级用户 Posts 175 Credits 338 | |
|
@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... |
|
| Floor15 qq152576450 | Posted 2008-08-25 10:15 |
| 新手上路 Posts 3 Credits 6 From 川 | |
|
```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 但不能判断是否重复.... 望前辈指教 ``` |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |