关于班级随机的问题 [英] question about class Random

查看:125
本文介绍了关于班级随机的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,



我想知道c#中的Random类如何生成随机数。事实上我想知道创建随机数的函数Next(MinValue,MaxValue)的结构。你知道我们所知道它实际上并不是随机的,但它的开发者就像一个随机生成器向我们展示它。



谢谢。

hi friends,

i want to know how Random class in c# generate random number. in fact i want to know structure of function Next(MinValue,MaxValue) that create random number.you know that all we know that it is not random in fact but developers of it show it to us like a random generator.

thanks.

推荐答案

正如韦斯所说,看看来源。



我刚刚在dotPeek中打开它,它看起来像这样,虽然我认为你需要研究整个课程的背景。



As Wes says, look at the source.

I've just opened it up in dotPeek and it looks like this, although I think you'd need to study the whole class for context.

public virtual int Next(int minValue, int maxValue)
{
  if (minValue > maxValue)
  {
    throw new ArgumentOutOfRangeException("minValue", Environment.GetResourceString("Argument_MinMaxValue", (object) "minValue", (object) "maxValue"));
  }
  else
  {
    long num = (long) maxValue - (long) minValue;
    if (num <= (long) int.MaxValue)
      return (int) (this.Sample() * (double) num) + minValue;
    else
      return (int) ((long) (this.GetSampleForLargeRange() * (double) num) + (long) minValue);
  }
}


这篇关于关于班级随机的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆