Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
mail me at [email ID removed]

C#
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();
  }
}
Posted
Updated 14-Oct-14 2:23am
v2
Comments
[no name] 14-Oct-14 8:20am    
No one is going to write a book for you to explain some code.
ZurdoDev 14-Oct-14 8:21am    
What part do you not understand?

 
Share this answer
 
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();

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?
 
Share this answer
 
Comments
Manfred Rudolf Bihy 14-Oct-14 9:23am    
You have seemed to miss the obvious point that OP is trying to reverse engineer some assembly. From the tags of the question it might be something about Unity3D. Look for "// ISSUE: unable to decompile the method." in "OP's" code.
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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900