当前位置: 首页>>代码示例>>C#>>正文


C# IRandom.NextBytes方法代码示例

本文整理汇总了C#中IRandom.NextBytes方法的典型用法代码示例。如果您正苦于以下问题:C# IRandom.NextBytes方法的具体用法?C# IRandom.NextBytes怎么用?C# IRandom.NextBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRandom的用法示例。


在下文中一共展示了IRandom.NextBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetGuid

        public static System.Guid GetGuid(IRandom rand)
        {
            byte[] buffer = new byte[16];
            rand.NextBytes(buffer);

            return new System.Guid(buffer);
        }
开发者ID:KCL5South,项目名称:KCLAutoPoco,代码行数:7,代码来源:RandomExtensions.cs

示例2: GetBinary

        public static System.Byte[] GetBinary(IRandom rand, int minLength, int maxLength)
        {
            int length = rand.Next(minLength, maxLength);
            byte[] result = new byte[length];
            rand.NextBytes(result);

            return result;
        }
开发者ID:KCL5South,项目名称:KCLAutoPoco,代码行数:8,代码来源:RandomExtensions.cs

示例3: GetDouble

        public static System.Double GetDouble(	IRandom rand, 
												System.Double min = System.Double.MinValue, 
												System.Double max = System.Double.MaxValue)
        {
            byte[] buffer = new byte[8];
            rand.NextBytes(buffer);

            System.Double result = System.BitConverter.ToDouble(buffer, 0);

            if(result < min)
                return min;
            else if(result >= max)
                return max - 1;
            else
                return result;
        }
开发者ID:KCL5South,项目名称:KCLAutoPoco,代码行数:16,代码来源:RandomExtensions.cs

示例4: MeasureChiSquared

        private static double MeasureChiSquared(IRandom random, int rounds)
        {
            var counts = new int[256];

            var bs = new byte[256];
            for (var i = 0; i < rounds; ++i)
            {
                random.NextBytes(bs);

                for (var b = 0; b < 256; ++b)
                {
                    ++counts[bs[b]];
                }
            }

            var mask = SecureRandom.GetSeed(1)[0];
            for (var i = 0; i < rounds; ++i)
            {
                random.NextBytes(bs);

                for (var b = 0; b < 256; ++b)
                {
                    ++counts[bs[b] ^ mask];
                }

                ++mask;
            }

            var shift = SecureRandom.GetSeed(1)[0];
            for (var i = 0; i < rounds; ++i)
            {
                random.NextBytes(bs);

                for (var b = 0; b < 256; ++b)
                {
                    ++counts[(byte)(bs[b] + shift)];
                }

                ++shift;
            }

            var total = 3 * rounds;

            double chi2 = 0;
            for (var k = 0; k < counts.Length; ++k)
            {
                var diff = ((double)counts[k]) - total;
                var diff2 = diff * diff;

                chi2 += diff2;
            }

            chi2 /= total;

            return chi2;
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:56,代码来源:SecureRandomTest.cs

示例5: BigInteger

        public BigInteger(
            int bitLength,
            int certainty,
            IRandom random)
        {
            if (bitLength < 2)
                throw new ArithmeticException("bitLength < 2");

            this.SignValue = 1;
            this.nBitLength = bitLength;

            if (bitLength == 2)
            {
                this.Magnitude = random.Next(2) == 0
                                     ? Two.Magnitude
                                     : Three.Magnitude;
                return;
            }

            int nBytes = GetByteLength(bitLength);
            var b = new byte[nBytes];

            int xBits = BitsPerByte*nBytes - bitLength;
            byte mask = rndMask[xBits];

            for (;;)
            {
                random.NextBytes(b);

                // strip off any excess bits in the MSB
                b[0] &= mask;

                // ensure the leading bit is 1 (to meet the strength requirement)
                b[0] |= (byte) (1 << (7 - xBits));

                // ensure the trailing bit is 1 (i.e. must be odd)
                b[nBytes - 1] |= 1;

                this.Magnitude = MakeMagnitude(b, 0, b.Length);
                this.nBits = -1;
                this.mQuote = -1L;

                if (certainty < 1)
                    break;

                if (CheckProbablePrime(certainty, random))
                    break;

                if (bitLength > 32)
                {
                    for (int rep = 0; rep < 10000; ++rep)
                    {
                        int n = 33 + random.Next(bitLength - 2);
                        this.Magnitude[this.Magnitude.Length - (n >> 5)] ^= (1 << (n & 31));
                        this.Magnitude[this.Magnitude.Length - 1] ^= ((random.Next() + 1) << 1);
                        this.mQuote = -1L;

                        if (CheckProbablePrime(certainty, random))
                            return;
                    }
                }
            }
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:63,代码来源:BigInteger.cs

示例6: GetInt64

        public static System.Int64 GetInt64(IRandom rand, 
											System.Int64 min = System.Int64.MinValue,
											System.Int64 max = System.Int64.MaxValue)
        {
            byte[] buffer = new byte[8];
            rand.NextBytes(buffer);

            System.Int64 result = System.BitConverter.ToInt64(buffer, 0);

            if(result < min)
                return min;
            else if(result >= max)
                return max - 1;
            else
                return result;
        }
开发者ID:KCL5South,项目名称:KCLAutoPoco,代码行数:16,代码来源:RandomExtensions.cs


注:本文中的IRandom.NextBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。