1. Many Methods on the Internet use time seeds, but in a very short time, this methodIneffective
Random r = new random (datetime. now. millisecond); Random counter = new random (unchecked (INT) (datetime. now. ticks> CTR); Random counter = new random (system. guid. newguid (). gethashcode ());
2. Use random and hashtable to achieve the desired effect perfectly.
The following is a random generation of three codes with different positive random numbers less than 3. The result is 0 1 2, 2 0 1, and so on, there will be no repeated numbers like 0 0 1.
String teststr; void ongui () {If (guilayout. button ("generate random number") {teststr = ""; hashtable = new hashtable (); system. random Rm = new system. random (); int rmnum = 3; for (INT I = 0; hashtable. count <rmnum; I ++) {int nvalue = RM. next (3); If (! Hashtable. containsvalue (nvalue) {hashtable. add (nvalue, nvalue); // Add (Key, value) teststr + = nvalue + "" ;}} guilayout. label (teststr );}