In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to achieve digital rain batch processing, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The code is as follows:
@ echo off
Color 0a
: start
Set num=0
Set "echos="
: num
Set / an a1=%random%%%3
If "% A1%" = "1" set "A1 ="
If "% A1" = = "2" set "A1 ="
If "% A1%" = "0" set / an a1=%random%%%2
Set echos=%echos%%a1%
Set / a num=%num%+1
If "% num%" = = "75" echo% echos%&&goto: start
Goto: num
Let me explain in detail.
The code is as follows:
@ echo off
:: turn off the echo (needless to say)
Color 0a
:: this sentence means to change the font color of the batch. 0a is the color code (see the Color command for details)
: start
Set num=0
:: define (redefine) the variable of num with a value of 0 (we use this variable to calculate the number of batch loops)
Set "echos="
:: define (redefine) the variable of echos, with a value of a space
: num
Set / an a1=%random%%%3
:: this sentence is very important, it can be said to be the core of the whole digital rain code
:: this sentence means to define a random number with a value below "3"
To limit the value of a random number, you must use the / a switch of the set command
For example, I want to define a variable of num, this variable is a random number, the cut must be less than 20, then the code is
:: set / a num=%random%%%20
:: the above is the complete code, if you do not use the / a switch to write set num=%random%%%20
:: then an error will occur
If "% A1%" = "1" set "A1 ="
This means that if the value of the variable A1 (that is, the random variable in the previous sentence) is 1, then the value of A1 is a space
:: Ps (I need to talk about it here)
The purpose of our program is to simulate digital rain
:: you may have seen digital rain, digital rain is not all 0 and 1, there is a gap in the middle, this sentence is to achieve this goal
The following sentence is for the same purpose
There is one last point to mention
I don't know if you found that without our previous sentence, I didn't use double quotes such as set num=0.
:: but this sentence set "A1 =" uses double quotation marks. Why?
:: in fact, the previous statement set num=0 can also be changed to set "num=0"
:: this seems to be quite standard. Is it possible to change set "A1 =" to set A1 =?
The answer is "No"
Because set A1 = this sentence, even if you add a space after the statement, the batch will not recognize it.
:: causes the value of A1 to be empty, and in batch processing, the value of the variable cannot be empty, so we use spaces instead
:: write as set "A1 ="
If "% A1" = = "2" set "A1 ="
If the A1 value is 2, then the A1 value is a space
If "% A1%" = "0" set / an a1=%random%%%2
This sentence means that if the value of the random variable A1 is 0, then the value of A1 will randomly take an integer below 2
In other words, if the A1 value is 0, then A1 randomly chooses the numbers 0 and 1
Set "echos=%echos%%a1%"
Here is what I call variable superposition
:: quotation marks are used because A1 can also be a space
The second is echos=%echos%.. This is the only part we're watching right now.
:: this sentence means to define the echos variable as the value of the variable echos and the variable A1
Are you a little dizzy
:: we set the echos variable as a space at the beginning of the program
:: so let's define echos as a space + variable A1.
Isn't it a little clearer?
:: let's use examples.
The variable echos is now a space. We use spaces instead.
Let's assume that the variable A1 is the number 1.
So this time the variable defines echos as [space] + 1.
:: so the value of echos after the statement is executed is a space followed by the number 1
: is that right? Is that clear? This sentence is actually the superposition of variables.
If the statement continues, the value of echos is "[space] 1", right?
Then the program executes A1 again, assuming that the value of A1 is the number 2
: so what set "echos=%echos%%a1%" means
Define the value of the variable echos as "[space] 1" + number 2, that is, "[space] 12"
::.
Set / a num=%num%+1
:: this sentence means that the value of the variable num is added by one (that is, it is cycled once)
If "% num%" = = "75" echo% echos%&&goto: start
Display a superimposed variable echos when the above statement is executed 75 times in a loop
In other words, the variable echos is displayed after looping the above statement 75 times.
Goto: num
:: jump to the tag num
All kinds of color codes with Color command
The above is all the contents of the article "how to achieve Digital Rain in batch processing". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.