To generate a random number in C#, you can use the Random class in the System namespace. Here's an example:
main.cs110 chars3 lines
In this example, a new instance of Random is created and assigned to the rnd variable. The Next method is then called on rnd, which generates a random integer between the first and second arguments passed to the method. In this case, the random number will be between 1 and 100 (inclusive).
You can adjust the arguments passed to Next to generate a random number within a different range.
gistlibby LogSnag