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"; }
int n = rand() % 1 + 0; will produce 0 always as rand() % 1 gives 0 ( rand()%a generates number between 0 to a-1 ).
random() function returns a floating-point, pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1) with approximately uniform distribution over that range — which you can then scale to your desired range.
A random number generator always returns a value between 0 and 1, but never equal to one or the other.
random() is what you are looking for: From python docs: random. random() Return the next random floating point number in the range [0.0, 1.0).
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).
If you want 50/50 probability, I suggest:
Random rand = new Random(); if (rand.NextDouble() >= 0.5) lnkEvents.CssClass = "selected"; else lnkNews.CssClass = "selected";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With