I am a little stuck with a simple Question: how to generate a simple random Boolean?
If am correct, a Boolean 0 = false and 1 = true
, but how to suse that?
Current code:
Dim RandGen As New Random
Dim RandBool As Boolean
RandBool = Boolean.Parse(RandGen.Next(0, 1).tostring)
Or just simply:
Random rng = new Random();
bool randomBool = rng.Next(0, 2) > 0;
Saves some processing power of parsing text, whereas a simple compare is enough.
Edit: Second parameter is exclusive, so should be .Next(0, 2)
.
Dim RandGen As New Random
Dim RandBool As Boolean
RandBool = RandGen.Next(0, 2).ToString
TextBox1.Text = RandBool
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