user3181941
user3181941

Reputation: 55

Generate random numbers to be used within a table using ASP.NET C#

I'm looking to create a 10x10 table in which the values are randomly generated from 1 to 20.

I have managed to create the table however I can't figure out how to make the value of a cell random, rather than a specific value.

How do I go about doing this?

Upvotes: 3

Views: 2130

Answers (1)

Deepak Bhatia
Deepak Bhatia

Reputation: 6276

Simple, use Random class,

    Random r = new Random();
    r.Next(1, 20);

A simple 2-D array example,

    int[,] arr = new int [10, 10];
    Random r = new Random();
    for (int ki = 0; ki < 10; i++)
    {
        for (int kj = 0; kj < 10; j++)
        {
            arr[ki, kj] = r.Next(1, 20);
        }
    }

Upvotes: 5

Related Questions