A few days ago, when I was working on a dating site (www.niyuewo.com), I encountered a duplicate member number problem. After searching for information on the Internet, I found it was a problem with the system timestamp, So I sorted it out, hope to help you
In C #, the random function calls the next method in system. Random to generate a random number. First, define a Random Seed, for example:
Int R; here, an initial value is usually assigned, and then the new random (r); R. next (INT macvalue) -- Note: The range of random numbers can be specified in brackets of the next method. Its usage is R. next (1,100) -- in 1 ~ A random positive integer is generated in 100.
In fact, if the above method is applied to Windows FormsProgramA bug occurs in the Click Event of the button in, that is, the random number is generated when the Click Event of the button is triggered for the first time. However, when you click the button for the second time, but it produces the same number as the previous one. How can this bug be solved? We need to use a system function datatime. Now. millisecond. Because the current time of the system will not be repeated, we can declare it as follows:
Int RA;
Random RD = new random (datetime. Now. millisecond );
Ra = RD. Next (1,100 );
In this way, the problem is solved successfully!