Random number: 0 or 1
问题 Am I looking too far to see something as simple as pick a number: 0 or 1? Random rand = new Random(); if (rand.NextDouble() == 0) { lnkEvents.CssClass = "selected"; } else { lnkNews.CssClass = "selected"; } 回答1: Random rand = new Random(); if (rand.Next(0, 2) == 0) lnkEvents.CssClass = "selected"; else lnkNews.CssClass = "selected"; Random.Next picks a random integer between the lower bound (inclusive) and the upper bound (exclusive). 回答2: If you want 50/50 probability, I suggest: Random rand