In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to use random numbers to write a class roll call machine", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article, let's take a look at this "C# how to use random numbers to write class roll call" article.
English meaning
What can random numbers do?
Generating random numbers has a wide range of uses, such as randomly selecting a record from a database, giving the generated numbers to variables, executing some code at a certain point in time, assigning random numbers to arrays, and so on.
Class roll call
For example, there is a form that requires roll call according to the seat number.
1. Create a Windows project
And then the next step is done.
two。 Drag control
If there is no toolbox in the view, it can be called up.
3. Write code
The code in the button
Random a = new Random (); / / create a random number string [] name = new string [6]; / / create a string numeric storage name name [1] = "Cai Xule"; name [2] = "Lubunda"; name [3] = "Li Yunyu"; name [4] = "Ma Dong Tu"; name [5] = "Bai Jukao" / / assign values to each element, / / the number in / / [] is their seat number / / that is, the number of elements in the array int b = a.Next (1Lame.Length); / / A random number is assigned to the b variable, returning a random number from 1 to 6 / / name.Length: the length of the array, which is as long as there are several elements
The array starts at 0 because you need to call the roll by seat number.
So the array needs more than 1 number, such as 60 people, then your array has to write 61.
Int b = a.Next (1dyname.length); / / Random number is assigned to variable b, returning a random number from 1 to 6 / / name.Length: the length of the array, as long as there are several elements.
Ok, run
Effect picture:
Each click is a different person.
Other uses
Random interval time
Random a = new Random (); int b = a.Next (1000, 5000); Thread.Sleep (b); MessageBox.Show ("Little Horse's coffin plate"); / / execute the window sentence at random intervals of 1-5 seconds
Random data extraction from database
Random a = new Random (); int b = a.Next (1, 5000); string str = "SELECT * FROM Table_2 WHERE id ='" + b + ""; above is the content of this article on "how to write a class roll call machine with random numbers". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please pay attention to 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: 281
*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.