Ejemplo n.º 1
0
        /// <summary>
        /// 获取N个没有中过奖的成员
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public List <CompanyMember> GetRandomMembers(LuckSetting luckSetting)
        {
            string full = string.Empty;
            List <CompanyMember> listMember = new List <CompanyMember>();

            for (int i = 0; i < luckSetting.count; i++)
            {
                CompanyMember member = GetRandomMember(luckSetting.level);
                if (member == null)
                {
                    continue;
                }
                member.isLuck   = true;
                member.luckName = luckSetting.name;
                full           += member.department + " " + member.name + "\r\n";
                listMember.Add(member);
            }

            //写出结果到本地
            if (Directory.Exists(@".\Result") == false)
            {
                Directory.CreateDirectory(@".\Result");
            }
            File.WriteAllText(@".\Result\" + luckSetting.name + "-" + DateTime.Now.Ticks + ".txt", full);


            return(listMember);
        }
Ejemplo n.º 2
0
        public List <CompanyMember> GetRandomMembersForShow(LuckSetting luckSetting)
        {
            List <CompanyMember> listMember = new List <CompanyMember>();

            if (luckSetting.count > m_listMember.Count)
            {
                luckSetting.count = m_listMember.Count;
            }

            while (listMember.Count < luckSetting.count)
            {
                CompanyMember member = GetRandomMember(luckSetting.level);
                if (member == null)
                {
                    continue;
                }
                //member.isLuck = true;
                //member.luckName = luckSetting.name;

                if (listMember.Contains(member) == false)
                {
                    listMember.Add(member);
                }
            }


            return(listMember);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取一个没有中过奖的成员
        /// </summary>
        /// <returns></returns>
        public CompanyMember GetRandomMember(int level)
        {
            //获取随机index

            for (int i = 0; i < 10000; i++) //这里避免出现调用卡住 所以设个次数
            {
                byte[] guidBytes = Guid.NewGuid().ToByteArray();
                int    theSeed   = BitConverter.ToInt32(guidBytes, 0);
                Random rd        = new Random(theSeed);
                int    index     = rd.Next(0, m_listMember.Count - 1);

                CompanyMember member = m_listMember[index];

                if (member.isLuck == false && member.level <= level)
                {
                    return(member);
                }
            }

            return(null); // GetRandomMember(level)
        }