0
I have a script to generate a certain amount of random Cpfs in a text file.
When executing the method that generates the random CPF within the while, the method is executed only once and always generates the same number in the text file.
using System;
using System.IO;
using geraCPF;
namespace geraTXT
{
public class TXT
{
public CPF geraRand;
[STAThread]
static void Main(string[] args)
{
CPF geraRand = new CPF();
//Informa o caminho e o nome do arquivo apra o construtor StreamWriter
StreamWriter sw = new StreamWriter(@"C:\Users\carol\Desktop\CPFs.txt");
//Escreve linhas no arquivo .txt
for (int i = 0; i < 10; i++)
{
sw.WriteLine(geraRand.cpfRandomico());
}
//Fecha o arquivo
sw.Close();
}
}
}
Script result:
48307261058
48307261058
48307261058
48307261058
48307261058
48307261058
48307261058
48307261058
48307261058
48307261058
What needs to be done for the method to be executed at each increment of the i++ in the while, thus generating a different number each time?
I want to know how to run the start method again, with each increment, to generate a different number.
How to run the start method again at each increment to generate a different number?
– CarolCiola
What is the implementation of the class
CPF? theRandomis instantiated in the constructor orcpfRandomicoof that class ? If it is in thecpfRandomicois exactly the problem that @Maniero linked to in the duplicate question.– Isac
@Isac, Random was being declared
varwithin the classcpfRandomico, hence the error. I instated out of class and worked.– CarolCiola