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
You can use this method on a
Random
object
https://learn.microsoft.com/en-us/dotnet/api/system.random.next?view=net-8.0#system-random-next(system-int32-system-int32)Random.Next Method (System)
Returns a random integer.
Random.Shared.Next()
preferablyI did it like that:
ty
You can do it like that, sure
Or just
Is there any chance to convert the int to a string? Just realized you cant put both in an if statement
.ToString()
Ty, works good
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);