这个代码如何工作plz解释 [英] how this code works plz explain

查看:584
本文介绍了这个代码如何工作plz解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

邮寄给我[电子邮件ID已删除]



mail me at [email ID removed]

using System;

public class RandomGenerator
{
  private const uint B = 1842502087U;
  private const uint C = 1357980759U;
  private const uint D = 273326509U;
  private static uint counter;
  private uint a;
  private uint b;
  private uint c;
  private uint d;

  public float value
  {
    get
    {
      // ISSUE: unable to decompile the method.
    }
  }

  public RandomGenerator(uint val)
  {
    base.\u002Ector();
    this.SetSeed(val);
  }

  public RandomGenerator()
  {
    base.\u002Ector();
    this.SetSeed(RandomGenerator.counter++);
  }

  public uint GenerateUint()
  {
    uint num = this.a ^ this.a << 11;
    this.a = this.b;
    this.b = this.c;
    this.c = this.d;
    return this.d = (uint) ((int) this.d ^ (int) (this.d >> 19) ^ ((int) num ^ (int) (num >> 8)));
  }

  public int Range(int max)
  {
    return (int) ((long) this.GenerateUint() % (long) max);
  }

  public int Range(int min, int max)
  {
    return min + (int) ((long) this.GenerateUint() % (long) (max - min));
  }

  public float Range(float min, float max)
  {
    return min + (max - min) * this.GenerateFloat();
  }

  public float GenerateFloat()
  {
    // ISSUE: unable to decompile the method.
  }

  public float GenerateRangeFloat()
  {
    return 4.656613E-10f * (float) (int) this.GenerateUint();
  }

  public double GenerateDouble()
  {
    return 0.0 * Math.PI * (double) this.GenerateUint();
  }

  public double GenerateRangeDouble()
  {
    return 4.65661287416159E-10 * (double) (int) this.GenerateUint();
  }

  public void SetSeed(uint val)
  {
    this.a = val;
    this.b = val ^ 1842502087U;
    this.c = val >> 5 ^ 1357980759U;
    this.d = val >> 7 ^ 273326509U;
    for (uint index = 0U; index < 4U; ++index)
      this.a = this.GenerateUint();
  }
}

推荐答案

尝试维基百科:Xorshift随机数生成器 [ ^ ]。
Try Wikipedia: "Xorshift random number generators"[^].


您是否知道逐行解释代码的工作量是多少?

每一行都需要一段解释!例如:

Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();



创建一个名为next的新变量,它可以包含一个整数值。从先前声明的Random实例r,调用Next方法获取一个新的随机数,并将其分配给next变量。



可以你想象我们需要多长时间才能解释一个像你的例子一样的非常短的代码片段,一行一行?



不会发生这种情况。如果您有特定问题,请询问有关它的问题。但首先考虑一下 - 您是否想要坐下45分钟并且没有充分理由键入逐行描述?


Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?


在对任何组件进行逆向工程之前,请确保你没有违反任何协议。

这段代码属于哪个软件套件?



干杯!
Before you go reverse engineering any assemblies, make sure that you are not violating any agreements.
To which software suite does this piece of code belong?

Cheers!


这篇关于这个代码如何工作plz解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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