public void Single_Distribution() { Distribution( 10, 1_000_000, () => Convert.ToInt32(Math.Truncate(r.NextSingle(0, 10))) ); }
public void TestNextSingle() { var random = new System.Random(54321); var average = Enumerable.Range(0, 20000).Select(_ => random.NextSingle()) .Average(); Assert.Equal(actual: average, expected: .5f, precision: 2); }
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]); } }
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")); } }); _navTimer = new Stopwatch(); MainWindow.SetScene(new MenuScene(Game)); }
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(); } }
public BsdfSample(Random rng) { UDir0 = rng.NextSingle(); UDir1 = rng.NextSingle(); UComponent = rng.NextSingle(); }
public LightSample(Random rng) { UPos0 = rng.NextSingle(); UPos1 = rng.NextSingle(); UComponent = rng.NextSingle(); }