public void Random_5_0to4expected()
        {
            int[] expected = (0, 1, 2, 3, 4);

            int actual = CryptoRandom.Random(5);

            CollectionAssert.Contains(expected, actual);
        }
        public IActionResult Random(char gender, char common, bool needSurname)
        {
            char        all         = 'у';
            List <Name> genderNames = new List <Name>();

            if (common == '3')
            {
                if (gender != 'а')
                {
                    genderNames = db.Names.Where(p => (p.Gender == gender || p.Gender == all)).ToList();
                }
                else
                {
                    genderNames = db.Names.ToList();
                }
            }
            else
            {
                if (common == '1')
                {
                    if (gender != 'а')
                    {
                        genderNames = db.Names.Where(p => p.Common == true).Where(p => (p.Gender == gender || p.Gender == all)).ToList();
                    }
                    else
                    {
                        genderNames = db.Names.Where(p => p.Common == true).ToList();
                    }
                }
                if (common == '2')
                {
                    List <Name> commonGenderNames = new List <Name>();
                    if (gender != 'а')
                    {
                        genderNames       = db.Names.Where(p => (p.Gender == gender || p.Gender == all)).ToList();
                        commonGenderNames = db.Names.Where(p => p.Common == true).Where(p => (p.Gender == gender || p.Gender == all)).ToList();
                    }
                    else
                    {
                        genderNames       = db.Names.ToList();
                        commonGenderNames = db.Names.Where(p => p.Common == true).ToList();
                    }
                    genderNames.AddRange(commonGenderNames);
                }
            }

            int randomNameId = CryptoRandom.Random(genderNames.Count);

            NameSurnameViewModel nameSurname = new NameSurnameViewModel();

            nameSurname.Name    = db.Names.FirstOrDefault(p => p.Id == genderNames[randomNameId].Id);
            nameSurname.Surname = new Surname()
            {
                RomanSurname = "", CyrilSurname = "", Common = false, Id = 0
            };
            if (needSurname)
            {
                List <Surname> surnamesList = new List <Surname>();
                surnamesList = dbs.Surnames.ToList();
                int randomSurnameId = CryptoRandom.Random(surnamesList.Count);
                nameSurname.Surname = dbs.Surnames.FirstOrDefault(p => p.Id == surnamesList[randomSurnameId].Id);
            }

            return(PartialView("/Views/Names/_Random.cshtml", nameSurname));
            //return PartialView("/Views/Home/Contact.cshtml");
        }
Beispiel #3
0
        public static string GetRandomName(string file_ext = "")
        {
            int length = (int)CryptoRandom.Random(64) + 32;

            return(GetRandomName(length) + file_ext);
        }