|
mwh79
初级用户
 
积分 86
发帖 27
注册 2005-9-25
状态 离线
|
『楼 主』:
如果我需要生成1到100之间的随机数,应该怎样写(完结)
使用 LLM 解释/回答一下
如果我需要生成1到100之间的随机数,应该怎样写
请教
有谁知道的吗,,用BAT来实现!!!
不使用=%random%
而是只在1到100起选取,提高效率!
搞定了,多谢了
Last edited by mwh79 on 2006-12-1 at 07:13 AM ]
If I need to generate a random number between 1 and 100, how should I write it?
Ask for advice.
Is there anyone who knows? Use BAT to implement it!!!
Do not use %random%, but only select from 1 to 100, and improve efficiency!
Got it, thank you.
Last edited by mwh79 on 2006-12-1 at 07:13 AM ]
|
|
2006-12-1 04:41 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
set /a RandomNumber=%random%%%100+1 (bat 中使用)
set /a RandomNumber=%random%%%100+1 (used in bat)
|
|
2006-12-1 04:47 |
|
|
mwh79
初级用户
 
积分 86
发帖 27
注册 2005-9-25
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
set /a RandomNumber=%random%%%100+1
运行不起来!
这样好象没有什么效率呀,,运行得到数,太慢了!
Last edited by mwh79 on 2006-12-1 at 04:53 AM ]
set /a RandomNumber=%random%%%100+1
It doesn't run!
This doesn't seem very efficient! It takes too long to get the number!
Last edited by mwh79 on 2006-12-1 at 04:53 AM ]
|
|
2006-12-1 04:51 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
%random%是随机出现的数字,而且是瞬间的,如果你的机器反应慢,那应该是你机器的问题
%random% is a randomly appearing number, and it's instantaneous. If your machine is slow, that should be an issue with your machine
|
|
2006-12-1 05:05 |
|
|
mwh79
初级用户
 
积分 86
发帖 27
注册 2005-9-25
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
不,主要是匹配的问题,如果要要生成95-97之间的随机数,,那就有可能,很久都得不到,
要看运气,,所以 我想把他固定在一个范围内!
No, it's mainly a matching problem. If you want to generate a random number between 95 and 97, then it's possible that it takes a long time to get it, it depends on luck. So I want to fix it within a range!
|
|
2006-12-1 05:10 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
|
2006-12-1 05:38 |
|
|
mwh79
初级用户
 
积分 86
发帖 27
注册 2005-9-25
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
谢谢..我看了一下,,
不过还是没有我需要的,,
他们的随机都是从1开始的,,,能不能实现重35开始到100结束,这样的语句,,跳过1~35这样应该就有效率些,,,,我怕的就是从98~100这样的随机,,什么时候才能碰运气生成出来呀!
Thanks..I took a look,,
But it's still not what I need,,
Their random numbers all start from 1,,,Can we implement a statement that starts from 35 and ends at 100, so as to skip 1~35, which should be more efficient,,,I'm worried that with random numbers from 98~100, when will the luck come to generate that!
|
|
2006-12-1 05:51 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
你还没看仔细
用%random%单纯获取某一区段的随机数是有效率问题,问题是你怎样使用%random%
You haven't looked carefully enough. Using %random% simply to obtain random numbers in a certain range has an efficiency issue. The problem is how you use %random%.
|
|
2006-12-1 05:56 |
|
|
mwh79
初级用户
 
积分 86
发帖 27
注册 2005-9-25
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
%random%可以获取某一个区域吗,,,我试过了很多参数,,现在可以控制最大价值,可是没有办法控制最小值
Can %random% obtain a certain range?,,, I have tried many parameters,,, now I can control the maximum value, but I can't control the minimum value
|
|
2006-12-1 06:02 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
@echo off
:loop
set /a RandomNumber=1%random:~-1%%random:~-1%-99
::最大值100
if %RandomNumber% LSS 35 goto loop
::小于35返回
if %RandomNumber% GTR 75 goto loop
::大于75返回
echo %RandomNumber%
if "%RandomNumber%" == "50" pause
goto loop
```@echo off
:loop
set /a RandomNumber=1%random:~-1%%random:~-1%-99
::Maximum value 100
if %RandomNumber% LSS 35 goto loop
::Return if less than 35
if %RandomNumber% GTR 75 goto loop
::Return if greater than 75
echo %RandomNumber%
if "%RandomNumber%" == "50" pause
goto loop
```
|
|
2006-12-1 06:07 |
|
|
mwh79
初级用户
 
积分 86
发帖 27
注册 2005-9-25
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
大哥,你的那个效率怎么样呀!!
:STARTIP
Set /a a=%RANDOM%%%250
IF %a% LEQ 100 goto startip
IF %a% GEQ 105 goto startip
我这样的很没有效率
Dude, how about the efficiency of yours??
:STARTIP
Set /a a=%RANDOM%%%250
IF %a% LEQ 100 goto startip
IF %a% GEQ 105 goto startip
Mine like this is very inefficient
|
|
2006-12-1 06:22 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by mwh79 at 2006-11-30 18:22:
大哥,你的那个效率怎么样呀!!
:STARTIP
Set /a a=%RANDOM%%%250
IF %a% LEQ 100 goto startip
IF %a% GEQ 105 goto startip
我这样的很没有效率
结果源于测试
Originally posted by mwh79 at 2006-11-30 18:22:
Dude, how's your efficiency!!
:STARTIP
Set /a a=%RANDOM%%%250
IF %a% LEQ 100 goto startip
IF %a% GEQ 105 goto startip
Mine is very inefficient like this
Result comes from testing
|
|
2006-12-1 06:24 |
|
|
mwh79
初级用户
 
积分 86
发帖 27
注册 2005-9-25
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
我测试下来,是一样的,,,,我其实想实现的是,,不是显示,,而是,只从35-100中间的数来读去,,,,1-34不读,,,这样可以做到马上就可以得到数据,不需要判断了!
I tested it and it's the same. Actually, what I want to achieve is not to display, but to only read the numbers from 35 to 100, and not read 1 to 34. In this way, I can get the data immediately without judgment!
|
|
2006-12-1 06:31 |
|
|
tianzizhi
高级用户
   
积分 622
发帖 214
注册 2006-9-22
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
取一定范围的数,
@echo off
::22是范围数,45是底数即开始的数,即楼主要求的最小数.,如取45-67之间的数,请注意格式,写错了就会出错,楼主说没有运行成功是因为格式错,还有取一段范围的数要用批处理实现,在cmd下会出错,在cmd取一随机数可以,就是只写%random%.
set /a c=%random% %% 22+45
echo %c%
::取随机两位数
set /a d=%random:~0,2%
echo %d%
::避免00
set /a e=1%random:~0,2%-100
echo %e%
Take numbers within a certain range,
@echo off
:: 22 is the range number, 45 is the base number, that is, the minimum number required by the owner. For example, if you want to take numbers between 45-67, please pay attention to the format. If it is wrong, it will go wrong. The owner said that it did not run successfully because the format was wrong. Also, to take a range of numbers, you need to implement it with batch processing. It will go wrong in cmd. It is okay to take a random number in cmd, that is, just write %random%.
set /a c=%random% %% 22+45
echo %c%
:: Take a random two-digit number
set /a d=%random:~0,2%
echo %d%
:: Avoid 00
set /a e=1%random:~0,2%-100
echo %e%
|
|
2006-12-1 06:39 |
|
|
mwh79
初级用户
 
积分 86
发帖 27
注册 2005-9-25
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
不错,谢谢,知道怎么些最小值了,,,
还有个问题
set /a c=%random% %% 22+45
这段中的两个数可以写成变量吗??
因为这样太不灵活了,太死,,手动改太麻烦,,,,
That's good, thank you. I know how to write the minimum value...
There's another question
set /a c=%random% %% 22+45
Can the two numbers in this segment be written as variables??
Because this is too inflexible and too rigid, and it's too cumbersome to modify manually....
|
|
2006-12-1 06:53 |
|
|