C
C#11mo 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
Angius11mo ago
Random.Shared.Next() preferably
LeNoX
LeNoXOP11mo 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
Angius11mo 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
LeNoXOP11mo ago
Is there any chance to convert the int to a string? Just realized you cant put both in an if statement
Angius
Angius11mo ago
.ToString()
LeNoX
LeNoXOP11mo ago
Ty, works good
ThatDaniel
ThatDaniel11mo 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