zoukankan      html  css  js  c++  java
  • C# 双色球选号

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;

    namespace ConsoleApplicationTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                Random random = new Random();
                for (int i = 0; i < 5; i++)
                {
                    Console.WriteLine(getLastNum(random));
                }
               
                Console.ReadKey();
            }

            static string getFirstNum(Random random)
            {
                string results = "";
                int[] range = new int[33];
                for (int i = 0; i < 33; i++)//初始化范围集合,从1到33
                {
                    range[i] = i + 1;
                }
                int[] result = CreateNumbers(random, range, 6);
                ArrayList al = new ArrayList();
                for (int i = 0; i < result.Length; i++)
                {
                    al.Add(result[i]);
                }
                al.Sort();
                for (int i = 0; i < result.Length; i++)
                {
                    if (Convert.ToInt32(al[i]) < 10)
                    {
                        al[i] = "0" + al[i].ToString();
                    }
                }
                results = al[0].ToString() + "," + al[1].ToString() + "," + al[2].ToString() + "," + al[3].ToString() + "," + al[4].ToString() + "," + al[5].ToString();
                return results;
            }

            static string getLastNum(Random random)
            {
                int num = random.Next(1, 12);
                string results = getFirstNum(random) + "+" + (num < 10 ? "0" + num.ToString() : num.ToString());
                return results;
            }

            //取出不重复的6个数
            static int[] CreateNumbers(Random random, int[] range, int count)
            {
                int[] result = new int[count];
                int index = 0;
                int temp = 0;
                for (int i = 0; i < count; i++)
                {
                    index = random.Next() % (range.Length - i);
                    result[i] = range[index];
                    //将当前已使用过的数移至集合末尾,并且将末尾原来没有使用的数放到当前位置
                    temp = range[range.Length - 1 - i];
                    range[range.Length - 1 - i] = range[index];
                    range[index] = temp;
                }
                return result;
            }

        }
    }

  • 相关阅读:
    redhat,centos Linux常用命令LS之常用功能
    人生信用卡
    如何让Redhat Linux启动时进入字符终端模式(不进入XWindow)
    OpenJDK和JDK区别
    Linux rpm 命令参数使用详解[介绍和应用]
    linux 的vim命令详解
    centos6.4安装javajdk1.8
    samba服务器 实现Linux与windows 文件共享
    SELinux 宽容模式(permissive) 强制模式(enforcing) 关闭(disabled) 几种模式之间的转换
    linux学习之 Linux下的Eclipse安装
  • 原文地址:https://www.cnblogs.com/xsmhero/p/2641658.html
Copyright © 2011-2022 走看看