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-01 11:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved] Ask about the usage of the system variable random View 2,184 Replies 3
Original Poster Posted 2011-01-20 20:08 ·  中国 广东 东莞 中移铁通
初级用户
★★
Credits 115
Posts 92
Joined 2010-12-24 16:57
15-year member
UID 179794
Gender Male
Status Offline
I searched the forum for a long time and still didn't figure out the usage of random. What do these mean?

set /a %%av=!random!%%40*2,%%ai=!random!%%30

set /a f=%random%%%14+1

Thanks!!!

[ Last edited by acaigg on 2011-1-24 at 20:10 ]
Floor 2 Posted 2011-01-22 17:14 ·  中国 上海 联通
新手上路
Credits 13
Posts 11
Joined 2010-08-24 11:36
15-year member
UID 172893
Gender Male
From 上海
Status Offline
Your code is wrong. There is no system variable called random. It must be a random variable set in the script.
Floor 3 Posted 2011-01-22 17:43 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
%RANDOM% returns any decimal number between 0 and 32767, generated by Cmd.exe.
%% is the modulus in batch set/a, that is, to get the remainder.
Using random, remainder, etc. in set/a is to make the obtained variable a regular random number.
set/a i=!random!%%30, i is a random number between 0 and 29;
set/a v=!random!%%40*2, v is an even number between 0 and 78;
set/a f=%random%%%14+1, f is a random number between 1 and 14.
Floor 4 Posted 2011-01-24 19:52 ·  中国 广东 东莞 中移铁通
初级用户
★★
Credits 115
Posts 92
Joined 2010-12-24 16:57
15-year member
UID 179794
Gender Male
Status Offline
Thank you very much for the explanation by Han Ye Gu Xing, which is very clear. Thank you again!!!
Forum Jump: