Hey guys. Im try to write a program with 3 major things which are two lists and a random.

what i want to do is say whatever values are in those lists then produce so many random value if you get what i mean.

so say list one value is 3, and list two is 4 than it should produce 12 random numbers.

I hope this doesnt sound too complicated. The reason I want to do this is shorten the code as much as possible.

Thanks

Hmmm, sounds like a homework assignment:)
It is fairly simple to accomplish though. I'm assuming your two lists have the values preset. So you just need to find the selected item of each list, convert to integer and multiply them.
Once you have that value a loop that includes that value as the maximum can be done that calculates a new random number each iteration of the loop.
Have a go and post up some code when you get stuck.

Nope not a homework assignment. Im not even in school lol. Just a bit self studying.

I'll have a bit a go at it now.

What is the actual problem?
So far, it's just multiplication to get a result, right?

using System;
using System.Collections.Generic;

namespace DW_405186_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         List<int> lst_intSeed1 = new List<int>() { 5, 1, 3, 2, 4 };
         List<int> lst_intSeed2 = new List<int>() { 4, 1, 7 };

         lst_intSeed1.ForEach(i =>
            lst_intSeed2.ForEach(j =>
               {
                  Console.WriteLine("{0} * {1} = {2}", i, j, (i * j));
               }));
      }
   }
}

...and then the "overkill"

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

namespace DW_405186_CS_CON
{
   class Program
   {
      static void Main(string[] args)
      {
         List<int> lst_intSeed1 = new List<int>() { 5, 1, 3, 2, 4 };
         List<int> lst_intSeed2 = new List<int>() { 4, 1, 7 };

         lst_intSeed1.ForEach(i =>
            lst_intSeed2.ForEach(j =>
               {
                  Console.Write("{0} * {1} = {2}:\n [ ", i, j, (i * j));
                  
                  Random rnd = new Random((int)DateTime.Now.Ticks % int.MaxValue);
                  
                  Enumerable.Range(1, (i * j)).ToList().ForEach(e => Console.Write("{0} ", rnd.Next(1, 100)));
                  
                  Console.WriteLine(']');
               }));
      }
   }
}

Edited 4 Years Ago by thines01: Added Code

My lists are doubles not ints and i have not tried to use an array. maybe i should.

My lists are doubles not ints

I'm confused. Just change them to doubles

and i have not tried to use an array. maybe i should.

What do you mean? What's wrong with a list?

It will only get more complicated with an array (or two).

Edited 4 Years Ago by thines01: clarity

This article has been dead for over six months. Start a new discussion instead.