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


C# Random.NextSingle方法代码示例

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


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

示例1: LatinHypercube

        public static void LatinHypercube(float[] samples, int nSamples, int nDim, Random rng)
        {
            // Generate LHS samples along diagonal
            float delta = 1.0f / nSamples;
            for (var i = 0; i < nSamples; ++i)
                for (var j = 0; j < nDim; ++j)
                    samples[nDim * i + j] = Math.Min((i + (rng.NextSingle())) * delta, OneMinusEpsilon);

            // Permute LHS samples in each dimension
            for (var i = 0; i < nDim; ++i)
                for (var j = 0; j < nSamples; ++j)
                {
                    var other = j + (rng.Next() % (nSamples - j));
                    MathUtility.Swap(ref samples[nDim * j + i], ref samples[nDim * other + i]);
                }
        }
开发者ID:modulexcite,项目名称:aether,代码行数:16,代码来源:MonteCarloUtilities.cs

示例2: OnInitialize

        protected override void OnInitialize()
        {
            var rand = new Random();

            Entity.Register("selection marker", ent => {
                ent.AddComponent<Render3D>()
                    .SetModel(EntityModel.Get("models", "selection"))
                    .SetOffset(new Vector3(0f, 1f / 8f, 0f))
                    .SetScale(0.5f);
                ent.ThinkExtended += (sender, e) => {
                    ent.GetComponent<Render3D>()
                        .SetRotation((float) (Math.PI * MainWindow.Time));
                };
            });

            Entity.Register("human", ent => {
                ent.AddComponent<RenderAnim>();
                ent.AddComponent<Collision>()
                    .SetDimentions(0.5f, 0.5f)
                    .SetModel(CollisionModel.Repel | CollisionModel.Entity);
                ent.AddComponent<Movement>();
                ent.AddComponent<Health>();
            });

            Entity.Register("survivor", "human", ent => {
                ent.AddComponent<Survivor>();
                ent.AddComponent<DeliberativeAI>()
                    .AddDesire<Entities.Desires.Wander>()
                    .AddDesire<Entities.Desires.ThreatAvoidance>()
                    .AddDesire<Entities.Desires.WallAvoidance>()
                    .AddDesire<Entities.Desires.Migration>()
                    .AddDesire<Entities.Desires.Mobbing>()
                    .AddDesire<Entities.Desires.Barricading>();
            });

            Entity.Register("zombie", "human", ent => {
                ent.AddComponent<Zombie>();
                ent.AddComponent<ZombieAI>();
            });

            Entity.Register("crate", ent => {
                ent.AddComponent<StaticTile>();
                ent.AddComponent<Health>();
                ent.AddComponent<WoodenBreakable>();
                ent.AddComponent<Collision>()
                    .SetDimentions(1.125f, 1.125f)
                    .SetModel(CollisionModel.Entity);
                ent.AddComponent<Render3D>()
                    .SetRotation(rand.NextSingle(-MathHelper.Pi / 16f, MathHelper.Pi / 16f))
                    .SetScale(
                        rand.NextSingle(0.75f, 0.9f),
                        rand.NextSingle(0.75f, 0.9f),
                        rand.NextSingle(0.75f, 0.9f));
            });

            Entity.Register("small crate", "crate", ent => {
                ent.GetComponent<Health>()
                    .SetMaximum(50)
                    .Revive();
                ent.GetComponent<WoodenBreakable>()
                    .SetMinPlanks(2)
                    .SetMaxPlanks(3);
                ent.GetComponent<Render3D>()
                    .SetModel(EntityModel.Get("models", "deco", "crate", "small"))
                    .SetSkin(rand);
            });

            Entity.Register("large crate", "crate", ent => {
                ent.GetComponent<Health>()
                    .SetMaximum(100)
                    .Revive();
                ent.GetComponent<WoodenBreakable>()
                    .SetMinPlanks(3)
                    .SetMaxPlanks(6);
                ent.GetComponent<Render3D>()
                    .SetModel(EntityModel.Get("models", "deco", "crate", "large"))
                    .SetSkin(rand);
            });

            Entity.Register("plank", ent => {
                ent.AddComponent<Plank>();
                ent.AddComponent<Render3D>()
                    .SetModel(EntityModel.Get("models", "deco", "plank"))
                    .SetSkin(rand)
                    .SetScale(
                        rand.NextSingle(0.75f, 0.9f),
                        rand.NextSingle(0.75f, 0.9f),
                        rand.NextSingle(0.75f, 0.9f));
            });

            Entity.Register("wood pile", ent => {
                ent.AddComponent<Collision>()
                    .SetDimentions(1.125f, 1.125f)
                    .SetModel(CollisionModel.Entity);

                var pile = ent.AddComponent<WoodPile>();

                int count = rand.Next(8) + 1;
                for (int i = 0; i < count; ++i) {
                    pile.AddPlank(Entity.Create(ent.World, "plank"));
//.........这里部分代码省略.........
开发者ID:alexturpin,项目名称:Zombles,代码行数:101,代码来源:ZomblesPlugin.cs

示例3: OnCityGenerated

        protected override void OnCityGenerated()
        {
            GameScene scene = MainWindow.CurrentScene as GameScene;
            World world = scene.World;
            Random rand = new Random();

            Func<Vector2> randPos = () => {
                Vector2 pos;
                do {
                    pos = new Vector2(rand.NextSingle() * world.Width, rand.NextSingle() * world.Height);
                } while (world.GetTile(pos).IsSolid);
                return pos;
            };

            for (int i = 0; i < scene.HumanCount; ++i) {
                Entity surv = Entity.Create(world, "survivor");
                surv.Position2D = randPos();

                surv.Spawn();
            }

            for (int i = 0; i < scene.ZombieCount; ++i) {
                Entity zomb = Entity.Create(world, "zombie");
                zomb.Position2D = randPos();
                zomb.Spawn();
            }
        }
开发者ID:alexturpin,项目名称:Zombles,代码行数:27,代码来源:ZomblesPlugin.cs

示例4: BsdfSample

 public BsdfSample(Random rng)
 {
     UDir0 = rng.NextSingle();
     UDir1 = rng.NextSingle();
     UComponent = rng.NextSingle();
 }
开发者ID:modulexcite,项目名称:aether,代码行数:6,代码来源:BsdfSample.cs

示例5: LightSample

 public LightSample(Random rng)
 {
     UPos0 = rng.NextSingle();
     UPos1 = rng.NextSingle();
     UComponent = rng.NextSingle();
 }
开发者ID:modulexcite,项目名称:aether,代码行数:6,代码来源:LightSample.cs


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