7
I’m making a program that draws 6 numbers (1 to 6) 1 million times and in the end shows how many times was drawn, but I have a doubt in the code, I’m optimizing in vectors not to use if
, but in the end it is considering the position 0 of the vector and the number 0 and ends up not drawing the number 6, only from 0 to 5, can help me see what is wrong?
Follow the code in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] numeros;
numeros = new int[6];
int randnum;
Random rdm = new Random();
for (int i = 0; i < 1000000; i++)
{
randnum = rdm.Next(6);
Console.WriteLine("girei pela: " + i + " vez");
numeros[randnum] = numeros[randnum] + 1;
}
for (int i = 0; i < numeros.Length; i++)
{
Console.WriteLine("Quantidade de vezes que o N° "+i+ " foi sorteado: " + numeros[i]);
}
Console.ReadKey();
}
}
}
Gee, I can understand! Thanks a lot for the help... I’m getting into this language now and I’m getting deeper. This part you put "1_000_000" separately, is for better reading of the number only? What is the function of "$" before the text?
– Airton Dambrovski
Yes, I used separator to give more readability. See https://answall.com/q/91117/101
– Maniero