|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 31 楼』:
使用 LLM 解释/回答一下
谢谢各位!辛苦了!!!
Thank you everyone! You've worked hard!!!
|
|
2007-1-5 11:10 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
 『第 32 楼』:
使用 LLM 解释/回答一下
实际上这是一个生成P(m,n)随机数列的问题
当m远大于n时可以采用楼上各位的碰撞式生成
但当n接近m时,碰撞生成效率极低
此时通常采用顺序数列随机排序或者顺序数列随机选取方法
下面是一个P(100,100)的例子,即生成100个互不重复的0~99之间的随机数列
:: 生成0-99之间的随机数列 R1
:: qzwqzw@bbs.cn-dos.net
:: 2007-01-04 23:03
@echo off
setlocal EnableDelayedExpansion
:: 初始化顺序数列
for /l %%i in (0,1,99) do (
set rnum%%i=%%i
)
:: 对数列进行随机交换
for /l %%i in (0,1,99) do (
set /a rnd=!random! %% 100
call set tmp=%%rnum!rnd!%%
set rnum!rnd!=!rnum%%i!
set rnum%%i=!tmp!
)
set rnum
pause
Actually, this is a problem of generating a random sequence of P(m, n).
When m is much larger than n, the collision - based generation method by the above - mentioned people can be adopted.
But when n is close to m, the collision generation efficiency is extremely low.
At this time, the sequential sequence random sorting or sequential sequence random selection method is usually adopted.
The following is an example of P(100, 100), that is, generating 100 non - repeated random sequences between 0 - 99.
:: Generate a random sequence R1 between 0 - 99
:: qzwqzw@bbs.cn-dos.net
:: 2007-01-04 23:03
@echo off
setlocal EnableDelayedExpansion
:: Initialize the sequential sequence
for /l %%i in (0,1,99) do (
set rnum%%i=%%i
)
:: Randomly swap the sequence
for /l %%i in (0,1,99) do (
set /a rnd=!random! %% 100
call set tmp=%%rnum!rnd!%%
set rnum!rnd!=!rnum%%i!
set rnum%%i=!tmp!
)
set rnum
pause
|
|
2007-1-5 12:15 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 33 楼』:
使用 LLM 解释/回答一下
@echo off
:start
cls
set Num=
set Tmp$=
:loop
set /a randomloop=%random%%%99+1
for %%n in (%Tmp$%) do if "%randomloop%" == "%%n" goto loop
call set Tmp$=%%Tmp$%% %randomloop%
set /a Num+=1
set random_%Num%=%randomloop%
if %Num% LSS 5 goto loop
for /l %%n in (1,1,%Num%) do call set /p= %%random_%%n%%<nul
echo.
pause
goto start
exit
可以“echo %Tmp$%”显示,也可以“set random_”显示
```
@echo off
:start
cls
set Num=
set Tmp$=
:loop
set /a randomloop=%random%%%99+1
for %%n in (%Tmp$%) do if "%randomloop%" == "%%n" goto loop
call set Tmp$=%%Tmp$%% %randomloop%
set /a Num+=1
set random_%Num%=%randomloop%
if %Num% LSS 5 goto loop
for /l %%n in (1,1,%Num%) do call set /p= %%random_%%n%%<nul
echo.
pause
goto start
exit
```
It can be displayed with "echo %Tmp$%" and also with "set random_".
|
|
2007-1-5 12:27 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 34 楼』:
使用 LLM 解释/回答一下
经过多次测试,发现13楼的代码很怪,结果中的五个数中的第一个数很容易和下一次测试结果中的第一个数相同,不知道是什么原因,可能代码有问题。
下面是我连续测试五遍的结果:
After multiple tests, it was found that the code on the 13th floor is very strange. The first number among the five numbers in the result is very likely to be the same as the first number in the next test result. I don't know the reason. Maybe there is a problem with the code.
The following are the results of my five consecutive tests:
附件
1: 1111.BMP (2007-1-6 01:47, 233.04 KiB, 下载附件所需积分 1 点
,下载次数: 6)
|
|
2007-1-6 01:47 |
|
|
tghksj
社区乞丐
此图片另存后死机
积分 -49
发帖 90
注册 2006-12-2
状态 离线
|
『第 35 楼』:
使用 LLM 解释/回答一下
又是 qzwqzw 我的偶像啊~~
32楼看不懂啊~~~~~我受不了了~你的每个代码我都得看上一两天...
求求你逐句解释一下行吗???妈妈密啊~~~受不了了~~!!!
----------------------------------
34楼你运气好,我这没出现这这样的情况.今天买张彩票试试!!一定中!!!!!:)
Last edited by tghksj on 2007-1-5 at 03:01 PM ]
It's qzwqzw again, my idol~~
I can't understand floor 32~~~~~ I can't take it anymore... I have to look at each of your codes for a day or two...
Please explain each sentence one by one, okay??? Mommiya~~~ can't take it anymore~!!!
----------------------------------
You're lucky on floor 34, I didn't have such a situation here. Buy a lottery ticket today and try!! Definitely win!!!!!:)
[[i] Last edited by tghksj on 2007-1-5 at 03:01 PM [/i]]
|

我的网络笔记本.[color=Red]非联系本人请勿访问![/color]http://w.vicp.net[img]http://zhenlove.com.cn/cndos/fileup/files/QM2.jpg[/img] |
|
2007-1-6 03:42 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 36 楼』:
使用 LLM 解释/回答一下
Originally posted by tghksj at 2007-1-5 14:42:
又是 qzwqzw 我的偶像啊~~
32楼看不懂啊~~~~~我受不了了~你的每个代码我都得看上一两天...
求求你逐句解释一下行吗???妈妈密啊~~~受不了了~~!!!
--- ...
晕,这跟运气有什么关系?我今天测试了N遍都是这样的情况。
Originally posted by tghksj at 2007-1-5 14:42:
Another idol of mine, qzwqzw~~
I can't understand the 32nd floor... I can't take it anymore... I have to read each of your codes for a day or two...
Please explain each sentence one by one, okay??? Mom, I can't take it anymore~!!!
--- ...
Oh, how does this have anything to do with luck? I tested it countless times today, and it's always like this situation.
|
|
2007-1-6 04:29 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 37 楼』:
使用 LLM 解释/回答一下
Originally posted by lxmxn at 2007-1-5 12:47:
经过多次测试,发现13楼的代码很怪,结果中的五个数中的第一个数很容易和下一次测试结果中的第一个数相同,不知道是什么原因,可能代码有问题。
我连试了十多次,间隔几分钟后再试也一样
Originally posted by lxmxn at 2007-1-5 12:47:
After multiple tests, I found that the code on floor 13 is very strange. The first number among the five numbers in the result is easily the same as the first number in the next test result. I don't know the reason. Maybe there is a problem with the code.
I tried it more than ten times, and it's the same after waiting for a few minutes and then trying again
|
|
2007-1-6 09:01 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 38 楼』:
使用 LLM 解释/回答一下
要显示1-100这个范围的随机数是极其简单的事情,问题的关键是要排除掉重复的数字,这样就增加了一些工作量。
It is extremely simple to display a random number in the range of 1-100. The key issue is to exclude duplicate numbers, which adds some workload.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-6 10:32 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 39 楼』:
使用 LLM 解释/回答一下
是啊,版主,你6楼的代码,经过多次测试,同样发现了重复的现象.
Yes, moderator, the code on your 6th floor, after multiple tests, I also found the phenomenon of duplication.
|
|
2007-1-6 10:50 |
|
|
balinger
中级用户
  
积分 356
发帖 115
注册 2004-7-27
状态 离线
|
『第 40 楼』:
使用 LLM 解释/回答一下
个人认为32 楼是唯一正解。先建立符合要求的的所有数码的顺序数列,再对顺序数列随机排列。随意取任意位,一定会同时满足不重复、随机的要求。其它思路,先取若干符合要求随机数码,再判断是否重复,理论上都有死循环的可能。
Personally, I think the 32nd floor is the only correct answer. First, establish all the ordered number sequences that meet the requirements, then randomly arrange the ordered sequences. Randomly taking any bit will definitely meet the requirements of no repetition and randomness. For other ideas, first take some random numbers that meet the requirements, then judge for repetition. Theoretically, there may be a possibility of an infinite loop.
|
|
2007-1-6 12:01 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 41 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2007-1-5 21:50:
是啊,版主,你6楼的代码,经过多次测试,同样发现了重复的现象.
不会吧?我已经通过 if not defined 语句来控制变量是否重复来排除重复的值了,从理论上来说是不可能有重复的值出现的,并且,经过我不小于100次的测试,始终没有发现重复值,请问你是如何多次重复测试的?
另外,在回这个帖子的过程中,突然明白了我在16楼所描述的奇怪现象是怎么造成的:原来,当num%num%从num1到num99这99个变量都被定义之后,第20次的第5个值应该是第100个值了,此时,可被利用的变量名都已经被定义过了,所以,程序只能在 loop 和 goto loop 之间打转转,造成了死循环。应当在适当的地方把所有的变量清空就可以解决16楼所说的奇怪问题了。
Originally posted by 26933062 at 2007-1-5 21:50:
Yes, moderator, I tested the code on floor 6 many times and found that there are still duplicate phenomena.
Is that so? I have used the if not defined statement to control whether the variable is duplicated to exclude duplicate values. Theoretically, there should be no duplicate values. Moreover, after I tested no less than 100 times, I never found duplicate values. How did you test and get duplicates many times?
In addition, while replying to this post, I suddenly understood how the strange phenomenon described in my 16th floor was caused: originally, when the num%num% from num1 to num99, these 99 variables are all defined, the 5th value of the 20th time should be the 100th value. At this time, all available variable names have been defined, so the program can only spin between loop and goto loop, causing an infinite loop. We should clear all variables appropriately to solve the strange problem described in the 16th floor.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-6 12:46 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 42 楼』:
使用 LLM 解释/回答一下
对6楼的代码稍作修改,使得代码可以重复N次而不会出现16楼所说的现象:
@echo off
:begin
cls
set times=0
set count=0
:loop
set /a num=%random%%%99+1
if not defined num%num% (
set num%num%=%num%
set /a count+=1
call echo %%num%%
)
set /a times+=1
if %times% equ 20 (
for /l %%i in (1,1,99) do set num%%i=
set times=0
)
if %count% lss 5 goto loop
pause>nul
goto begin
Modify the code on floor 6 slightly so that the code can repeat N times without the phenomenon mentioned in floor 16:
@echo off
:begin
cls
set times=0
set count=0
:loop
set /a num=%random%%%99+1
if not defined num%num% (
set num%num%=%num%
set /a count+=1
call echo %%num%%
)
set /a times+=1
if %times% equ 20 (
for /l %%i in (1,1,99) do set num%%i=
set times=0
)
if %count% lss 5 goto loop
pause>nul
goto begin
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-1-6 13:07 |
|
|
dikex
高级用户
    潜水修练批处理
积分 788
发帖 366
注册 2006-12-31
状态 离线
|
『第 43 楼』:
使用 LLM 解释/回答一下
凑凑热闹也发一个
@echo off
set count=1
set num=
echo %random% >nul
:DORND
set /a rnd=%random%*100/32767+1
echo %num% | find " %rnd% " && goto DORND
set num=%num% %rnd%
set /a count+=1
if %count% lss 6 goto DORND
echo %num%
pause
各位看到第四行可能会觉得奇怪,关于这个请看下面xmxn的提问和我的个人见解
Originally posted by lxmxn at 2007-1-5 12:47 PM:
经过多次测试,发现13楼的代码很怪,结果中的五个数中的第一个数很容易和下一次测试结果中的第一个数相同,不知道是什么原堮..
这个貌似是产生随机数的方法有问题,直接连续多次运行下面的语句
@echo off
set count=1
:loop
echo %random% & echo.
set /a count+=1
if %count% lss 10 goto loop
pause
这是我们会发现几次连续运行第一个出来的数字大小慢慢地增大,而之后的没有问题,时间间隔长一点第一个数的增幅就大一点,难道这个产生随机数的方法是于时间之类的有联系?随机产生的原数字大小差不多,经过某些运算后得到的结果一样也不为奇了,如果是这样的话,把第一个随机数舍弃或者使用另外一个运算就可以了
Just join in the fun and post one too
@echo off
set count=1
set num=
echo %random% >nul
:DORND
set /a rnd=%random%*100/32767+1
echo %num% | find " %rnd% " && goto DORND
set num=%num% %rnd%
set /a count+=1
if %count% lss 6 goto DORND
echo %num%
pause
Everyone may feel strange when seeing the fourth line. For this, please see the following question from xmxn and my personal insights
Originally posted by lxmxn at 2007-1-5 12:47 PM:
After multiple tests, it is found that the code on floor 13 is very strange. The first number among the five numbers in the result is very easy to be the same as the first number in the next test result. I don't know what the reason is..
This seems to be a problem with the method of generating random numbers. Directly run the following statement continuously for several times
@echo off
set count=1
:loop
echo %random% & echo.
set /a count+=1
if %count% lss 10 goto loop
pause
We will find that the first number that comes out gradually increases after several consecutive runs, and there is no problem later. If the time interval is longer, the increase of the first number will be larger. Is this method of generating random numbers related to time? The original random numbers are of similar sizes, and it is not surprising that the results obtained after certain operations are the same. If this is the case, discarding the first random number or using another operation can solve the problem
|
|
2007-1-6 14:02 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 44 楼』:
使用 LLM 解释/回答一下
Originally posted by dikex at 2007-1-6 01:02:
凑凑热闹也发一个
各位看到第四行可能会觉得奇怪,关于这个请看下面xmxn的提问和我的个人见解
这个貌似是产生随机数的方法有问题 ...
这个猜想有点问题吧??
看下面的代码:按理说来,for命令的执行速度是非常快的,但是下面代码所产生的随机数大小变化却是比较大的,是不是就排除了“随机数的产生和时间有关”这一说?
@echo off&setlocal enabledelayedexpansion
for /l %%a in (1,1,20) do echo !random!
pause
Originally posted by dikex at 2007-1-6 01:02:
Just to join in the fun, I'll post one too
Everyone may find the fourth line strange. For this, please see the following question from xmxn and my personal insights
This seems to be a problem with the method of generating random numbers...
There might be a problem with this conjecture?
Look at the following code: According to reason, the execution speed of the for command is very fast, but the size change of the random numbers generated by the following code is relatively large. Does this rule out the saying that "the generation of random numbers is related to time"?
@echo off&setlocal enabledelayedexpansion
for /l %%a in (1,1,20) do echo !random!
pause
|
|
2007-1-6 14:25 |
|
|
dikex
高级用户
    潜水修练批处理
积分 788
发帖 366
注册 2006-12-31
状态 离线
|
『第 45 楼』:
使用 LLM 解释/回答一下
嗯,有道理……
又一个猜想出现了^_^
可能时间只是产生时的其中一个参数,还与上一个随机数有关,而上一个经过某些放大差别以及和时间相关的运算后,第二个就是名副其实的随机了
总之%random%产生随机数的方法有点问题,各位使用时注意一下,必要时舍弃第一个随机数
P.S.听过某人说vb产生随机数也是很特殊的,不知和这个是否差不多,猜想……猜想……继续猜想……
Well, that makes sense...
Another conjecture emerges ^_^
Maybe time is just one of the parameters at the time of generation, and it is also related to the previous random number. After the previous one undergoes some amplified differences and operations related to time, the second one is truly random.
In short, there is something wrong with the way %random% generates random numbers. Everyone should be careful when using it. Discard the first random number if necessary.
P.S. Heard that someone said that the way VB generates random numbers is also very special. I wonder if it's similar to this. Conjecture... Conjecture... Continue to conjecture...
|
|
2007-1-6 14:41 |
|