+ 6

How to generate random number?

How to generate random number (for example, between 0 and 10) in C#?

26th May 2017, 2:44 PM
boyd
boyd - avatar
5 odpowiedzi
+ 22
// Random class is used for this purpose. Random rnd = new Random(); int foundation = rnd.Next(0, 10); // This generates numbers from 0-10;
26th May 2017, 2:48 PM
Dev
Dev - avatar
+ 14
@Mark Don't get me wrong. Yes, it excludes 10. This is what he asked. Random numbers between 0 and 10....What are you actually trying to describe me?
26th May 2017, 3:57 PM
Dev
Dev - avatar
+ 7
Thanks Dayve. I am quite okay to answer Python questions though
26th May 2017, 3:07 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
@Dayve I am a beginner so I could be mistaken, but in java I believe the random class will generate a number between 0 and 10 as you said, but 0 inclusive 10 excluded. so it would be 0-9 if you said new Random(0, 10). Is it different in c#? just curious 😉
26th May 2017, 3:53 PM
Mark Paramonte
Mark Paramonte - avatar
+ 6
I was more or less asking for my own benefit. it's nice to know that the random class works the same in c# as it does in java. I was told they were similar languages.
26th May 2017, 4:03 PM
Mark Paramonte
Mark Paramonte - avatar