In C#, you can use the Random
class to generate random numbers. To generate a random number between 1 and 10, you can use the Next
method of the Random
class along with the arguments 1 and 11 (11 is exclusive and will not be included in the range). Here's an example:
main.cs69 chars3 lines
In this example, we created a new instance of the Random
class and called the Next
method with the arguments 1 and 11. This will generate a random integer between 1 and 10, which we store in the randomNumber
variable.
gistlibby LogSnag