
1 文本格式
using System;
namespace Legalsoft.Truffer
 {
     /// <summary>
     /// Generator for random bytes using the algorithm generally known as RC4.
     /// </summary>
     public class Ranbyte
     {
         private int[] s { get; set; } = new int[256];
         private int i { get; set; }
         private int j { get; set; }
         private int ss { get; set; }
         private uint v { get; set; }
        public Ranbyte(int u)
         {
             v = (uint)(2244614371U ^ u);
             for (i = 0; i < 256; i++)
             {
                 s[i] = i;
             }
             for (j = 0, i = 0; i < 256; i++)
             {
                 ss = s[i];
                 j = (int)((j + ss + (v >> 24)) & 0xff);
                 s[i] = s[j];
                 s[j] = ss;
                 v = (uint)((v << 24) | (v >> 8));
             }
             i = j = 0;
             for (int k = 0; k < 256; k++)
             {
                 int8();
             }
         }
        public byte int8()
         {
             i = (i + 1) & 0xff;
             ss = s[i];
             j = (j + ss) & 0xff;
             s[i] = s[j];
             s[j] = ss;
             return (byte)(s[(s[i] + s[j]) & 0xff]);
         }
        /// <summary>
         /// Returns a random 32-bit integer constructed from 4 random bytes. Slow!
         /// </summary>
         /// <returns></returns>
         public uint int32()
         {
             v = 0;
             for (int k = 0; k < 4; k++)
             {
                 i = (i + 1) & 0xff;
                 ss = s[i];
                 j = (j + ss) & 0xff;
                 s[i] = s[j];
                 s[j] = ss;
                 v = (uint)((uint)(v << 8) | (uint)(s[(s[i] + s[j]) & 0xff]));
             }
             return v;
         }
        /// <summary>
         /// Returns a random double-precision floating value between 0. and 1. Slow!!
         /// </summary>
         /// <returns></returns>
         public double doub()
         {
             return 2.32830643653869629E-10 * (int32() + 2.32830643653869629E-10 * int32());
         }
     }
 }
  
2 代码格式
using System;
namespace Legalsoft.Truffer
{
    /// <summary>
    /// Generator for random bytes using the algorithm generally known as RC4.
    /// </summary>
    public class Ranbyte
    {
        private int[] s { get; set; } = new int[256];
        private int i { get; set; }
        private int j { get; set; }
        private int ss { get; set; }
        private uint v { get; set; }
        public Ranbyte(int u)
        {
            v = (uint)(2244614371U ^ u);
            for (i = 0; i < 256; i++)
            {
                s[i] = i;
            }
            for (j = 0, i = 0; i < 256; i++)
            {
                ss = s[i];
                j = (int)((j + ss + (v >> 24)) & 0xff);
                s[i] = s[j];
                s[j] = ss;
                v = (uint)((v << 24) | (v >> 8));
            }
            i = j = 0;
            for (int k = 0; k < 256; k++)
            {
                int8();
            }
        }
        public byte int8()
        {
            i = (i + 1) & 0xff;
            ss = s[i];
            j = (j + ss) & 0xff;
            s[i] = s[j];
            s[j] = ss;
            return (byte)(s[(s[i] + s[j]) & 0xff]);
        }
        /// <summary>
        /// Returns a random 32-bit integer constructed from 4 random bytes. Slow!
        /// </summary>
        /// <returns></returns>
        public uint int32()
        {
            v = 0;
            for (int k = 0; k < 4; k++)
            {
                i = (i + 1) & 0xff;
                ss = s[i];
                j = (j + ss) & 0xff;
                s[i] = s[j];
                s[j] = ss;
                v = (uint)((uint)(v << 8) | (uint)(s[(s[i] + s[j]) & 0xff]));
            }
            return v;
        }
        /// <summary>
        /// Returns a random double-precision floating value between 0. and 1. Slow!!
        /// </summary>
        /// <returns></returns>
        public double doub()
        {
            return 2.32830643653869629E-10 * (int32() + 2.32830643653869629E-10 * int32());
        }
    }
}



















