當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。