zoukankan      html  css  js  c++  java
  • 有规律的随机数

    using System;
    using System.Collections;

    namespace RandomDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                Hashtable ht0 = new Hashtable();
                for (int i = 0; i < 6; i++)
                {
                    do
                    {
                        Random rnd = new Random((unchecked((int)(DateTime.Now.Ticks))));
                        int tmp = rnd.Next(0, 100);
                        if (!ht0.ContainsValue(tmp))
                        {
                            ht0.Add(i, tmp);
                            break;
                        }
                    }
                    while (true);
                }
                Console.WriteLine("===============");
                foreach (var item in ht0.Values)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("===============");


                Hashtable ht1 = new Hashtable();
                for (int i = 0; i < 6; i++)
                {
                    do
                    {
                        Random rnd = new Random(Guid.NewGuid().GetHashCode());
                        int tmp = rnd.Next(0, 100);
                        if (!ht1.ContainsValue(tmp))
                        {
                            ht1.Add(i, tmp);
                            break;
                        }
                    }
                    while (true);
                }
                Console.WriteLine("===============");
                foreach (var item in ht1.Values)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("===============");

                Console.ReadKey();
            }


        }
    }

    结果1:

    ===============
    65
    90
    15
    41
    66
    91
    ===============
    ===============
    91
    97
    92
    30
    90
    12
    ===============

    结果2:

    ===============
    25
    72
    19
    66
    13
    60
    ===============
    ===============
    70
    26
    48
    16
    77
    86
    ===============

    结果3:

    ===============
    76
    51
    26
    75
    50
    24
    ===============
    ===============
    39
    33
    28
    83
    53
    50
    ===============

    结果4:

    ===============
    13
    88
    63
    38
    12
    87
    ===============
    ===============
    87
    92
    73
    6
    88
    11
    ===============

    结果5:

    ===============
    29
    4
    78
    53
    28
    2
    ===============
    ===============
    64
    65
    46
    35
    94
    53
    ===============

    结果6:

    ===============
    32
    57
    83
    8
    33
    59
    ===============
    ===============
    86
    54
    38
    84
    37
    58
    ===============

    So! How to get random numbers?

  • 相关阅读:
    [HAOI2015]按位或
    【bzoj 4675】 点对游戏
    [WC2013]糖果公园
    [国家集训队]数颜色 / 维护队列
    【bzoj 3252】攻略
    [ZJOI2016]小星星
    hdu-1712 ACboy needs your help---分组背包
    hdu-2844&&POJ-1742 Coins---多重背包
    UVA-147 Dollars---完全背包+打表
    hdu-2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活---多重背包
  • 原文地址:https://www.cnblogs.com/lucienbao/p/RegularRandomNumber.html
Copyright © 2011-2022 走看看