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


C# Random.NextInteger方法代码示例

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


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

示例1: RandomizedMassSceneUpdate2

        public void RandomizedMassSceneUpdate2()
        {
            const int NumberOfSceneNodes = 10;
              const int NumberOfSteps = 10000;
              const float WorldSize = 1000;

              var random = new Random(123457);
              var scene = new Scene();
              scene.EnableMultithreading = false;

              var nodes = new TestSceneNode[NumberOfSceneNodes];

              // Create random nodes.
              for (int i = 0; i < NumberOfSceneNodes; i++)
              {
            var node = new TestSceneNode();
            nodes[i] = node;

            var position = random.NextVector3F(0, WorldSize);
            var orientation = random.NextQuaternionF();
            node.PoseLocal = new Pose(position, orientation);

            float p = random.NextFloat(0, 100);
            if (p < 0.1f)
              node.Shape = Shape.Empty;
            else if (p < 0.2f)
              node.Shape = Shape.Infinite;
            else if (p < 0.6f)
              node.Shape = new BoxShape(random.NextVector3F(0, WorldSize));
            else
              node.Shape = new SphereShape(random.NextFloat(0, WorldSize));
              }

              var projection = new PerspectiveProjection();
              projection.SetFieldOfView(0.8f, 1, WorldSize / 10000, WorldSize);
              var camera = new Camera(projection);
              var cameraNode = new CameraNode(camera);

              for (int updateIndex = 0; updateIndex < NumberOfSteps; updateIndex++)
              {
            int actionsPerFrame = random.NextInteger(0, 100);
            for (int i = 0; i < actionsPerFrame; i++)
            {
              var node = nodes[random.Next(0, NumberOfSceneNodes)];

              const int numberOfActions = 100;
              int action = random.Next(0, numberOfActions);

              //scene.Validate();

              if (action == 0)
              {
            // Add
            if (node.Parent == null)
            {
              scene.Children.Add(node);
              //scene.Validate();
            }
              }
              else if (action == 1)
              {
            // Remove
            if (node.Parent != null)
            {
              node.Parent.Children.Remove(node);
              //scene.Validate();
            }
              }
              else if (action == 2)
              {
            // Move
            var pose = node.PoseWorld;
            pose.Position = random.NextVector3F(0, WorldSize);
            node.PoseWorld = pose;
            //scene.Validate();
              }
              else if (action == 3)
              {
            // Very small Move
            var pose = node.PoseWorld;
            const float maxDistance = WorldSize / 10000;
            pose.Position += random.NextVector3F(-maxDistance, maxDistance);
            node.PoseWorld = pose;
            //scene.Validate();
              }
              else if (action == 4)
              {
            // Small Move
            var pose = node.PoseWorld;
            const float maxDistance = WorldSize / 100;
            pose.Position += random.NextVector3F(-maxDistance, maxDistance);
            node.PoseWorld = pose;
            //scene.Validate();
              }
              else if (action == 5)
              {
            // Scale
            node.ScaleLocal = random.NextVector3F(0.0f, 10f);
            //scene.Validate();
              }
//.........这里部分代码省略.........
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:101,代码来源:SceneTest.cs


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