![]() |
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-09-10 06:39 |
47,812 topics / 349,914 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » Randomly display 5 different numbers |
| Printable Version 7,210 / 57 |
| Floor1 26933062 | Posted 2007-01-04 16:12 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
Can you display 5-digit numbers randomly from 1 to 100 at once without repetition?
I've thought about it for a long time and searched most of the posts in the forum, but it seems there are no posts that display 5-digit numbers at once, and the key is that there should be no repetition. Sorry, I'm sorry everyone. It seems my expression ability is really problematic. My purpose is to display random numbers from 1 to 100, display 5 at a time, and the 5 numbers displayed should not be repeated. Can everyone understand this? First of all, thank you all for your wonderful answers. Because my batch processing level is really too low, I can't understand some advanced answers well, so please forgive me if there are any wrong evaluations..................... 1. The answer on the 6th floor basically meets the requirements, but there is an occasional dead loop phenomenon when used multiple times. I don't know the reason. 2. The one on the 13th floor has no repetition phenomenon, but the first digit is always the same every time it runs, and I always feel a little inappropriate. 3. The one on the 26th floor can also be used, but it feels too rigid. (I'm sorry, maybe the wording is inappropriate, but I can't think of a more euphemistic word, please forgive me!) For example, if I want to display 6, 7, 8, 9... digits, it's too troublesome. In fact, my original intention is to first require entering the maximum value of the random number, and then entering the number of digits to display. 4. Personally, I feel that (in terms of thinking) the one on the 32nd floor should be the most ideal, but unfortunately I can't understand it, and the brother on the 32nd floor didn't write the code as required. (Displayed 100 at once). 5. I think the code on the 33rd floor should be the best. Judging from the code, there should be absolutely no repetition, and it is very flexible. I just don't know if there will be the problems they said about low efficiency and dead loops. Currently, the running condition is good. size] Sorry, moderator. After repeated testing, your method on the 6th floor is okay, but there will be a dead loop. Maybe I tested too many methods and got the wrong object. I'm sorry. The method modified on the 42nd floor I think is close to perfect. There are so many good methods, batch processing is really a challenge to people's thinking . [ Last edited by 26933062 on 2007-1-6 at 10:07 PM ] |
|
| Floor2 a9319751 | Posted 2007-01-04 20:42 |
| 中级用户 Posts 170 Credits 439 | |
|
5 digits? 5-digit?
1-100 has 5 digits |
|
| Floor3 zh159 | Posted 2007-01-04 22:17 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
5 randomly selected numbers from 1 to 99
1: 2: [ Last edited by zh159 on 2007-1-4 at 10:09 AM ] |
|
| Floor4 youxi01 | Posted 2007-01-04 23:45 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
Come to join in the "fun"
|
|
| Floor5 namejm | Posted 2007-01-05 01:52 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
The expression of the owner is problematic. After reading for a long time, I still don't know whether it is to generate 1-99 different random 5-digit numbers or to randomly display 5 different numbers in 1-99. Please make the owner's expression clear.
|
|
| Floor6 namejm | Posted 2007-01-05 02:16 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
After looking at the code on floor 4, it is inferred that the original intention of youxi01 was to display 5 different random numbers between 1 and 99 (excluding 99), but there is a problem with the code: %a% is a number from 1 to 5, and using if not defined to judge whether the variable num%a% has been defined, the execution result is always not defined.
Modify the code according to the idea of floor 4 as follows: —————————————————————————————————————— If this code is called in a loop, it will fall into an infinite loop at the 20th time. For the specific situation, please refer to the description in floor 16. For the cause analysis, please refer to floor 41, and for the code to solve the problem, please refer to floor 42. [ Last edited by namejm on 2007-1-6 at 05:03 PM ] |
|
| Floor7 tghksj | Posted 2007-01-05 03:05 |
| 社区乞丐 Posts 90 Credits -49 | |
|
Doubt about my own comprehension ability and the LZ's expression ability
Is it 5 numbers or 5 digits? 5 numbers from 1 to 100 as follows: |
|
| Floor8 namejm | Posted 2007-01-05 03:33 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
I have discovered that many people have overlooked such a detail: %random:~-2% might take the string "00". Although set /a num=%random:~-2% can convert the "00" string into a numerical value, turning it into 0, however, 0 is not what the original poster wanted.
|
|
| Floor9 tghksj | Posted 2007-01-05 04:30 |
| 社区乞丐 Posts 90 Credits -49 | |
|
Okay,
%random:~-2% doesn't work, then %random:~0,2% Ensure there's no 0 in front |
|
| Floor10 ccwan | Posted 2007-01-05 04:36 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Do the 5 numbers obtained include duplicates?
|
|
| Floor11 namejm | Posted 2007-01-05 04:41 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
According to the building楼主's statement, there should be no duplicate numbers among the 5 numbers.
|
|
| Floor12 ccwan | Posted 2007-01-05 04:43 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
At present, this situation has been found on the 9th floor.
|
|
| Floor13 tghksj | Posted 2007-01-05 06:18 |
| 社区乞丐 Posts 90 Credits -49 | |
|
OK!!!Nested recursion! This time it won't repeat, right??? Hehe
[ Last edited by tghksj on 2007-1-4 at 06:11 PM ] |
|
| Floor14 tghksj | Posted 2007-01-05 06:44 |
| 社区乞丐 Posts 90 Credits -49 | |
|
Oh my god~~ I'm stupid, why didn't I think of if not defined
Dizzy dizzy dizzy dizzy dizzy dizzy dizzy dizzy dizzy dizzy dizzy dizzy dizzy dizzy dizzy Hey?????????? Doesn't work????????????? There are still duplicates??! Experts explain it... Only the 13th floor is available for the time being.... [ Last edited by tghksj on 2007-1-4 at 05:53 PM ] |
|
| Floor15 namejm | Posted 2007-01-05 06:58 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
After looking at the code on floor 14, I found that there is no statement to control whether random numbers are repeated. After testing several times, you will find that repeated values appear. It is recommended to refer to the code I posted on floor 6.
|
|
| 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |