dimanche 14 juin 2015

Two Arrays of Non-Duplicate Numbers

I have the following code which generates two non-duplicates arrays of integers based on a ratio. The codes works perfectly but for a 4000 line file, this takes some time.

//Train & Test numbers
int train = (int)(((double)Settings.Default.TrainingRatio / 100) * inputLines.Count());
int test = inputLines.Count() - train;

//Train & Test list
Random rnd = new Random();
var trainList = Enumerable.Range(1, inputLines.Count()).OrderBy(x => rnd.Next()).Take(train).ToList();
var testList = new List<int>();
for (int i = 1; i <= inputLines.Count(); i++)
{
    if (!trainList.Contains(i))
        testList.Add(i);
}

And even worse, this is how i read those lines:

foreach (var n in trainList)
{
    objDataintilizer.GenerateMasterLableFile(inputLines.Skip(n - 1).Take(1).First().ToString());
}

Could anyone advice another way that could have a better performance.




Aucun commentaire:

Enregistrer un commentaire