Marz Nova

Marz Nova

  • NA
  • 4
  • 430

C# Looping through array bug (NEWBIE)

Feb 2 2018 1:09 PM
I can't figure out why this works if I step through it but when I run it, it will only give me a result such as :
4
4
4
4
4
4
4
4
4
4
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace ConsoleApplication1  
  8. {  
  9.     class Program  
  10.   
  11.     {  
  12.   
  13.         public static int diceRoller(int x, int y)  
  14.         {  
  15.             Random rnd = new Random();  
  16.             int result = rnd.Next(x, y+1);  
  17.             return result;  
  18.         }  
  19.   
  20.         static void Main(string[] args)  
  21.         {  
  22.   
  23.             int[] myArray = new int[10];  
  24.   
  25.             for (int i = 0; i < myArray.Length; i++)  
  26.             {  
  27.                 myArray[i] = diceRoller(1, 6);  
  28.   
  29.                 Console.WriteLine(myArray[i]);    
  30.             }  
  31.   
  32.             Console.ReadKey();  
  33.   
  34.         }  
  35.     }  
  36. }  
 

Answers (1)