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


C# Random.NextBigInteger方法代码示例

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


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

示例1: NextBigIntegerTest

        public void NextBigIntegerTest()
        {
            Random rand = new Random();

            byte[] aaa = new byte[] { 10, 20, 30, 40, 50 };
            byte[] bbb = aaa.Reverse().ToArray();
            bool isSqeEq = bbb.SequenceEqual(new byte[] { 50, 40, 30, 20, 10 });
            Assert.IsTrue(isSqeEq);

            BigInteger b0 = rand.NextBigInteger(0);
            BigInteger b1 = rand.NextBigInteger(1);
            BigInteger b2 = rand.NextBigInteger(2);
            BigInteger b3 = rand.NextBigInteger(100);
            BigInteger b4 = rand.NextBigInteger(BigInteger.Pow(2, 127));

            Assert.IsTrue(b0 >= 0);
            Assert.IsTrue(b0 == 0);
            Assert.IsTrue(b1 >= 0);
            Assert.IsTrue(b1 < 1);
            Assert.IsTrue(b2 >= 0);
            Assert.IsTrue(b2 < 2);
            Assert.IsTrue(b3 >= 0);
            Assert.IsTrue(b3 < 100);
            Assert.IsTrue(b4 >= 0);
            Assert.IsTrue(b4 < BigInteger.Pow(2, 130));

            try
            {
                BigInteger b5 = rand.NextBigInteger(-BigInteger.Pow(2, 127));
                Assert.Fail();
            }
            catch (Exception ex) { }
        }
开发者ID:vhst,项目名称:Prime_Numbers_Generator,代码行数:33,代码来源:UnitTestGenerator.cs

示例2: testUnionAndTimestamp

        public void testUnionAndTimestamp()
        {
            List<OrcProto.Type> types = new List<OrcProto.Type>();
            types.Add(OrcProto.Type.CreateBuilder().SetKind(OrcProto.Type.Types.Kind.STRUCT).
                AddFieldNames("time").AddFieldNames("union").AddFieldNames("decimal").
                AddSubtypes(1).AddSubtypes(2).AddSubtypes(5).Build());
            types.Add(OrcProto.Type.CreateBuilder().SetKind(OrcProto.Type.Types.Kind.TIMESTAMP).
                Build());
            types.Add(OrcProto.Type.CreateBuilder().SetKind(OrcProto.Type.Types.Kind.UNION).
                AddSubtypes(3).AddSubtypes(4).Build());
            types.Add(OrcProto.Type.CreateBuilder().SetKind(OrcProto.Type.Types.Kind.INT).
                Build());
            types.Add(OrcProto.Type.CreateBuilder().SetKind(OrcProto.Type.Types.Kind.STRING).
                Build());
            types.Add(OrcProto.Type.CreateBuilder().SetKind(OrcProto.Type.Types.Kind.DECIMAL).
                Build());

            ObjectInspector inspector = OrcStruct.createObjectInspector(0, types);

            HiveDecimal maxValue = HiveDecimal.Parse("10000000000000000000");
            OrcStruct row = new OrcStruct(3);
            OrcUnion union = new OrcUnion();
            Random rand;

            using (Stream file = FileOpenWrite(TestFilePath))
            using (Writer writer = OrcFile.createWriter(TestFilePath, file, OrcFile.writerOptions(conf)
                .inspector(inspector)
                .stripeSize(1000)
                .compress(CompressionKind.NONE)
                .bufferSize(100)
                .blockPadding(false)))
            {
                row.setFieldValue(1, union);
                row.setFieldValue(0, Timestamp.Parse("2000-03-12 15:00:00"));
                HiveDecimal value = HiveDecimal.Parse("12345678.6547456");
                row.setFieldValue(2, value);
                union.set((byte)0, 42);
                writer.addRow(row);
                row.setFieldValue(0, Timestamp.Parse("2000-03-20 12:00:00.123456789"));
                union.set((byte)1, "hello");
                value = HiveDecimal.Parse("-5643.234");
                row.setFieldValue(2, value);
                writer.addRow(row);
                row.setFieldValue(0, null);
                row.setFieldValue(1, null);
                row.setFieldValue(2, null);
                writer.addRow(row);
                row.setFieldValue(1, union);
                union.set((byte)0, null);
                writer.addRow(row);
                union.set((byte)1, null);
                writer.addRow(row);
                union.set((byte)0, 200000);
                row.setFieldValue(0, Timestamp.Parse("1970-01-01 00:00:00"));
                value = HiveDecimal.Parse("10000000000000000000");
                row.setFieldValue(2, value);
                writer.addRow(row);
                rand = new Random(42);
                for (int i = 1970; i < 2038; ++i)
                {
                    row.setFieldValue(0, Timestamp.Parse(i + "-05-05 12:34:56." + i));
                    if ((i & 1) == 0)
                    {
                        union.set((byte)0, (i * i));
                    }
                    else
                    {
                        union.set((byte)1, (i * i).ToString());
                    }
                    value = HiveDecimal.create(rand.NextBigInteger(64), rand.Next(18));
                    row.setFieldValue(2, value);
                    if (maxValue.CompareTo(value) < 0)
                    {
                        maxValue = value;
                    }
                    writer.addRow(row);
                }
                // let's add a lot of constant rows to test the rle
                row.setFieldValue(0, null);
                union.set((byte)0, 1732050807);
                row.setFieldValue(2, null);
                for (int i = 0; i < 5000; ++i)
                {
                    writer.addRow(row);
                }
                union.set((byte)0, 0);
                writer.addRow(row);
                union.set((byte)0, 10);
                writer.addRow(row);
                union.set((byte)0, 138);
                writer.addRow(row);
                writer.close();

                TypeDescription schema = writer.getSchema();
                Assert.Equal(5, schema.getMaximumId());
                bool[] expected = new bool[] { false, false, false, false, false, false };
                bool[] included = OrcUtils.includeColumns("", schema);
                Assert.Equal(expected, included);

                expected = new bool[] { false, true, false, false, false, true };
//.........这里部分代码省略.........
开发者ID:CurtHagenlocher,项目名称:OrcSharp,代码行数:101,代码来源:TestOrcFile.cs

示例3: testUnionAndTimestamp

        public void testUnionAndTimestamp()
        {
            TypeDescription schema = TypeDescription.createStruct()
                .addField("time", TypeDescription.createTimestamp())
                .addField("union", TypeDescription.createUnion()
                    .addUnionChild(TypeDescription.createInt())
                    .addUnionChild(TypeDescription.createString()))
                .addField("decimal", TypeDescription.createDecimal()
                    .withPrecision(38)
                    .withScale(18));
            HiveDecimal maxValue = HiveDecimal.Parse("10000000000000000000");
            Random rand = new Random(42);

            using (Stream file = File.OpenWrite(TestFilePath))
            using (Writer writer = OrcFile.createWriter(TestFilePath, file, OrcFile.writerOptions(conf)
                .setSchema(schema)
                .stripeSize(1000)
                .compress(CompressionKind.NONE)
                .bufferSize(100)
                .blockPadding(false)))
            {
                VectorizedRowBatch batch = schema.createRowBatch();
                batch.size = 6;
                setUnion(batch, 0, Timestamp.Parse("2000-03-12 15:00:00"), 0, 42, null,
                         HiveDecimal.Parse("12345678.6547456"));
                setUnion(batch, 1, Timestamp.Parse("2000-03-20 12:00:00.123456789"),
                    1, null, "hello", HiveDecimal.Parse("-5643.234"));

                setUnion(batch, 2, null, null, null, null, null);
                setUnion(batch, 3, null, 0, null, null, null);
                setUnion(batch, 4, null, 1, null, null, null);

                setUnion(batch, 5, Timestamp.Parse("1970-01-01 00:00:00"), 0, 200000,
                    null, HiveDecimal.Parse("10000000000000000000"));
                writer.addRowBatch(batch);

                batch.reset();
                for (int i = 1970; i < 2038; ++i)
                {
                    Timestamp ts = Timestamp.Parse(i + "-05-05 12:34:56." + i);
                    HiveDecimal dec = HiveDecimal.create(rand.NextBigInteger(64), rand.Next(18));
                    if ((i & 1) == 0)
                    {
                        setUnion(batch, batch.size++, ts, 0, i * i, null, dec);
                    }
                    else
                    {
                        setUnion(batch, batch.size++, ts, 1, null, (i * i).ToString(), dec);
                    }
                    if (maxValue.CompareTo(dec) < 0)
                    {
                        maxValue = dec;
                    }
                }
                writer.addRowBatch(batch);
                batch.reset();

                // let's add a lot of constant rows to test the rle
                batch.size = 1000;
                for (int c = 0; c < batch.cols.Length; ++c)
                {
                    batch.cols[c].setRepeating(true);
                }
                setUnion(batch, 0, null, 0, 1732050807, null, null);
                for (int i = 0; i < 5; ++i)
                {
                    writer.addRowBatch(batch);
                }

                batch.reset();
                batch.size = 3;
                setUnion(batch, 0, null, 0, 0, null, null);
                setUnion(batch, 1, null, 0, 10, null, null);
                setUnion(batch, 2, null, 0, 138, null, null);
                writer.addRowBatch(batch);
                schema = writer.getSchema();
            }

            Reader reader = OrcFile.createReader(TestFilePath, OrcFile.readerOptions(conf));

            Assert.Equal(5, schema.getMaximumId());
            bool[] expected = new bool[] { false, false, false, false, false, false };
            bool[] included = OrcUtils.includeColumns("", schema);
            Assert.Equal(expected, included);

            expected = new bool[] { false, true, false, false, false, true };
            included = OrcUtils.includeColumns("time,decimal", schema);
            Assert.Equal(expected, included);

            expected = new bool[] { false, false, true, true, true, false };
            included = OrcUtils.includeColumns("union", schema);
            Assert.Equal(expected, included);

            Assert.Equal(0, reader.getMetadataKeys().Count);
            Assert.Equal(5077, reader.getNumberOfRows());
            DecimalColumnStatistics stats =
                (DecimalColumnStatistics)reader.getStatistics()[5];
            Assert.Equal(71, stats.getNumberOfValues());
            Assert.Equal(HiveDecimal.Parse("-5643.234"), stats.getMinimum());
            Assert.Equal(maxValue, stats.getMaximum());
//.........这里部分代码省略.........
开发者ID:CurtHagenlocher,项目名称:OrcSharp,代码行数:101,代码来源:TestVectorOrcFile.cs


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