C
C#10mo ago
LeNoX

Getting a random number from 1 to 10

Hey, I am new to c sharp and I was wondering how can I get a random number from 1 to 10
8 Replies
Angius
Angius10mo ago
Random.Shared.Next() preferably
LeNoX
LeNoXOP10mo ago
I did it like that:
Random random = new Random();
int randomNumber = random.Next(1, 10);
Random random = new Random();
int randomNumber = random.Next(1, 10);
ty
Angius
Angius10mo ago
You can do it like that, sure Or just
int randomNumber = Random.Shared.Next(1, 10);
int randomNumber = Random.Shared.Next(1, 10);
LeNoX
LeNoXOP10mo ago
Is there any chance to convert the int to a string? Just realized you cant put both in an if statement
Angius
Angius10mo ago
.ToString()
LeNoX
LeNoXOP10mo ago
Ty, works good
ThatDaniel
ThatDaniel10mo ago
just fyi that will get you 1-9 as the second parameter is exclusive if you actually want to get 10 as a possibility then you'd need Random.Shared.Next(1, 11);
Want results from more Discord servers?
Add your server