System.Random.Random C# (CSharp) Method

Random() public method

public Random ( int Seed ) : System
Seed int
return System
      public Random(int Seed) {
        int ii;
        int mj, mk;
    
        //Initialize our Seed array.
        //This algorithm comes from Numerical Recipes in C (2nd Ed.)
        mj = MSEED - Math.Abs(Seed);
        SeedArray[55]=mj;
        mk=1;
        for (int i=1; i<55; i++) {  //Apparently the range [1..55] is special (Knuth) and so we're wasting the 0'th position.
          ii = (21*i)%55;
          SeedArray[ii]=mk;
          mk = mj - mk;
          if (mk<0) mk+=MBIG;
          mj=SeedArray[ii];
        }
        for (int k=1; k<5; k++) {
          for (int i=1; i<56; i++) {
        SeedArray[i] -= SeedArray[1+(i+30)%55];
        if (SeedArray[i]<0) SeedArray[i]+=MBIG;
          }
        }
        inext=0;
        inextp = 21;
        Seed = 1;
      }
    

Same methods

Random::Random ( ) : System

Usage Example

示例#1
0
 public static BigInteger Random(this System.Random generator, BigInteger limit)
 {
     return(new BigInteger(generator.Random(limit.Value)));
 }
All Usage Examples Of System.Random::Random