Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

takes a random number from list with a collection

I have a C# console application that takes a random bsn(sofi number) but now I have it that it shuffles the list and takes the first. But I want that it takes a random number from the list. Because of performance.

I have it like this:

    var selectRandomBsnNumber = HelperManager.BrpPersoonReposHelper2.GetAll()                
        .OrderBy(x => Guid.NewGuid())
        .Select(p => p.Bsn)
        .First().Count();

I try it like this:

int takeRanomBsnNumber = 0;

        var selectRandomBsnNumber = HelperManager.BrpPersoonReposHelper2.GetAll()                
            .OrderBy(x => Guid.NewGuid())
            .Select(p => p.Bsn)
            .Take(takeRanomBsnNumber)
            .First().Count();

this is the method:

public virtual IQueryable<TEntity> GetAll()
        {
            return Repository.GetAll();
        }

So this works:

 var selectRandomBsnNumber = HelperManager.BrpPersoonReposHelper2.GetAll()
                .OrderBy(x => Guid.NewGuid())
                .Select(p => p.Bsn)                
                .First();

But is very slow

Comments