Skip to content

Multiple Random Numbers

Christopher

Asked Jun 19, 2010, 9:23 AM EDT1 answer
Share
LinkedInX
Hi there,

I'm a noob, so please dumb it down for me.

I'm trying to output multiple random numbers.

Why doesn't the code below work?



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lab5Ex_2
{
    class Program
    {
        static void Main(string[] args)
        {

            for (int z = 0; z < 36; z++)
            {

                Random RandomNumber = new Random();

                int answer = RandomNumber.Next(1, 6);
                int answer2 = RandomNumber.Next(1, 6);

                int total = answer + answer2;



                Console.WriteLine(answer + " and " + answer2);
                Console.WriteLine("The total is " + total);
            }
            Console.Read();

        }
    }
}

Thanks for taking a look,

Chris

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I figured it out if anyone was interested:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace Lab5Ex_2
    {
        class Program
        {
            static Random RandomNumber = new Random();

            static void Main(string[] args)
            {
                int bigNumber = 15;
                int randomNumber1;
                int randomNumber2;
                int counter = 0;


                while (counter <= bigNumber)
                {
                    randomNumber1 = RandomNumber.Next(1, 7);
                    Console.Write(randomNumber1);

                    randomNumber2 = RandomNumber.Next(1, 7);
                    Console.WriteLine(randomNumber2);
                   
                    counter++;
                }


                Console.Read();
            }
        }
    }
    0