To generate a random number between 1 and 100 in C#, you can use the Random
class provided by the .NET framework. Here's a code snippet that does just that:
main.cs200 chars4 lines
Explanation:
Random
object that we'll use to generate the random number.Next
method of the Random
object, passing in the lower and upper bounds of the random number we want to generate (1 and 101, respectively). Note that the upper bound (101) is exclusive, so the generated number can be any integer in the range [1, 100].Console.WriteLine
.gistlibby LogSnag