随机数字(支持int64,支持double)

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

namespace exam1
{

    class Program
    {

        static void Main(string[] args)
        {
            while (true)
            {
                Run run = new Run();
                run.Do();
                Console.WriteLine(是否要继续吗?(yn));
                string cin = Console.ReadLine();
                if (cin == y  cin == Y)
                {
                    continue;
                }
                else
                {
                    break;
                }

            }

        }

    }

    public class Run
    {

        const int Min32 = -2147483648;
        const int Max32 = 2147483647;
        public double max = 0;
        public void Do()
        {
            Console.WriteLine(输入最小值:);
            string sx = Console.ReadLine();
            Console.WriteLine(输入最大值:);
            string sy = Console.ReadLine();
            Console.WriteLine(要产生数据个数:);
            long number = long.Parse(Console.ReadLine());
            if (double.Parse(sx)  double.Parse(sy))  9 - 5
            {
                Console.WriteLine(最小值不能大于最大值!);
            }
            else if (double.Parse(sx) == double.Parse(sy))  10000-10000
            {
                Console.WriteLine(double.Parse(sx));
            }

            else
            {
                if (sx.IndexOf(.)  0 && sy.IndexOf(.)  0)   1000 - 100000
                {
                    long x = long.Parse(sx);
                    long y = long.Parse(sy);

                    for (int l = 0; l  number; l++)
                    {
                        Console.WriteLine(Rl(x, y));
                    }
                }
                else
                {
                    if (sx.IndexOf(.)  0 && sy.IndexOf(.)  0)   1.3333  - 2
                    {
                        long x = long.Parse(sx.Substring(0, sx.IndexOf(.)));
                        long y = long.Parse(sy);
                        for (int i = 0; i  number; i++)
                        {
                            string nn = (Rl(x, y) + Rd()).ToString();
                            Console.WriteLine(nn);
                        }
                    }

                    if (sx.IndexOf(.)  0 && sy.IndexOf(.)  0) 1 - 1.3333333  2 - 6.3333333
                    {
                        long x = long.Parse(sx) - 1;
                        long y = long.Parse(sy.Substring(0, sy.IndexOf(.)));
                        for (int i = 0; i  number; i++)
                        {
                            string nn = (Rl(x, y) + Rd()).ToString();
                            Console.WriteLine(nn);
                        }
                    }
                    if (sx.IndexOf(.)  0 && sy.IndexOf(.)  0)   2.3333333 - 3.3333333   5.66666 - 6.9999999
                    {
                        long x = long.Parse(sx.Substring(0, sx.IndexOf(.)));
                        long y = long.Parse(sy.Substring(0, sy.IndexOf(.)));
                        long dx = long.Parse(sx.Substring(sx.IndexOf(.) + 1, sx.Length - sx.IndexOf(.) - 1));
                        long dy = long.Parse(sy.Substring(sy.IndexOf(.) + 1, sy.Length - sy.IndexOf(.) - 1));

                        if (dx = dy)     0.66666 - 0.9999999    0.6666 - 0.6666
                        {
                            for (int i = 0; i  number; i++)
                            {
                                string nn = Rl(x, y).ToString() + . + Rl(dx, dy).ToString();
                                Console.WriteLine(nn);
                            }
                        }
                        else  5.99999 - 4.33333
                        {
                            for (int i = 0; i  number; i++)
                            {
                                string nn = (Rl(x, y) + Rd()).ToString();
                                Console.WriteLine(nn);
                            }
                        }

                    }

                }
            }
             Console.ReadKey();
        }

         summary
         int 32 随机数计算
         summary
         param name=x1最小值param
         param name=y2最大值param
         returnsreturns
        public static int R(int x1, int y2)
        {
            Thread.Sleep(100);
            Random random = new Random();
            int num = random.Next(x1, y2);
            return num;
        }

         summary
         int 32 随机数计算
         summary
         param name=xyparam
         returnsreturns
        public static int R(int xy)
        {
            Thread.Sleep(100);
            Random random = new Random();
            int num = random.Next(xy);
            return num;
        }
        public static double Rd()
        {
            Thread.Sleep(100);
            Random random = new Random();
            double num = random.NextDouble();

            return num;
        }

         summary
         int64 随机数计算
         summary
         param name=minparam
         param name=maxparam
         returnsreturns
        public static long Rl(long min, long max)
        {
            if (Min32 = min && max = Max32)
            {
                max = R(int.Parse(Convert.ToString(min)), int.Parse(Convert.ToString(max)));
            }
            else
            {
                long lon = max - min;
                long lon1 = lon - Max32;
                lon = lon1 + R(Max32);
                max = max - lon;
            }

            return max;
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值