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


C# Random.NextFloat方法代码示例

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


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

示例1: StratifiedSample4D

        public static void StratifiedSample4D( float[] samples,
            int offset, int nx, int ny, int nu, int nv,
            bool jitter, Random random )
        {
            float dx = 1.0f / nx;
            float dy = 1.0f / ny;
            float du = 1.0f / nu;
            float dv = 1.0f / nv;

            int k = offset;
            for( int v = 0; v < nv; ++v )
            {
                for( int u = 0; u < nu; ++u )
                {
                    for( int y = 0; y < ny; ++y )
                    {
                        for( int x = 0; x < nx; ++x )
                        {
                            float jx = jitter ? random.NextFloat() : 0.5f;
                            float jy = jitter ? random.NextFloat() : 0.5f;
                            float ju = jitter ? random.NextFloat() : 0.5f;
                            float jv = jitter ? random.NextFloat() : 0.5f;

                            samples[ k ] = ( x + jx ) * dx;
                            samples[ k + 1 ] = ( y + jy ) * dy;
                            samples[ k + 2 ] = ( u + ju ) * du;
                            samples[ k + 3 ] = ( v + jv ) * dv;

                            k += 4;
                        }
                    }
                }
            }
        }
开发者ID:jiawen,项目名称:libcgt.net,代码行数:34,代码来源:SamplingUtils.cs

示例2: Plant

 public Plant(int id, Random random)
 {
     Id = id;
     X = random.NextFloat(0, 300f);
     Z = random.NextFloat(0, 300f);
     Species = AvailableSpecies[random.Next(0, AvailableSpecies.Length)];
 }
开发者ID:AIScots,项目名称:EcoDevView,代码行数:7,代码来源:Plant.cs

示例3: AIKart

 public AIKart(int kartNum, Level level, byte[][,] weight)
 {
     rand = new Random(kartNum);
     Level = level;
     Weight = weight;
     position = new Vector3(rand.NextFloat(-10, 11), rand.NextFloat(-10, 11), rand.NextFloat(-10, 11));
 }
开发者ID:dualdragoon,项目名称:Unnamed-Racing-Game,代码行数:7,代码来源:AI.cs

示例4: NebulaParameters

 public NebulaParameters(Random rng)
 {
     Color = rng.NextRandomColor();
     Offset = new Vector2(rng.Next(-1000, 1000), rng.Next(-1000, 1000));
     Falloff = rng.NextFloat(3, 6);
     Intensity = (float)(rng.NextDouble() * 0.2 + 1.0);
     Scale = rng.NextFloat(0.01f, 4f);
 }
开发者ID:raycrasher,项目名称:Fell-Sky,代码行数:8,代码来源:SpaceBackgroundGeneratorService.cs

示例5: Animal

 public Animal(int id, Random random)
 {
     Id = id;
     X = random.NextFloat(0, 300f);
     Z = random.NextFloat(0, 300f);
     Species = AvailableSpecies[random.Next(0, AvailableSpecies.Length)];
     Name = $"{Species} {Id}";
 }
开发者ID:AIScots,项目名称:EcoDevView,代码行数:8,代码来源:Animal.cs

示例6: PointerData

 public PointerData(SharpDX.Direct2D1.DeviceContext context, uint id, PointerDeviceType type, Point p)
 {
     this.PointerId = id;
     this.DeviceType = type;
     this.Pointers = new List<Point>();
     this.Pointers.Add(p);
     Random rnd = new Random();
     // Colors of lines. presents in RGBA (a random value between 0.5 ~ 1.0)
     color = new Color4(rnd.NextFloat(0.5f, 1), rnd.NextFloat(0.5f, 1), rnd.NextFloat(0.5f, 1), 1);
 }
开发者ID:j796160836,项目名称:MultiTouchTest,代码行数:10,代码来源:PointerData.cs

示例7: generate_input_file_content

 public static string[] generate_input_file_content(int seed)
 {
     string[] data = new string[2];
     Random rand = new Random(seed);
     string operation = rand.Next(0, 4).ToString();
     string num0 = rand.NextFloat().ToString();
     string num1 = rand.NextFloat().ToString();
     data[0] = operation;
     data[1] = num0 + " " + num1;
     return data;
 }
开发者ID:McArren,项目名称:MathNTests,代码行数:11,代码来源:ContentGenerator.cs

示例8: FloorTest

        public void FloorTest()
        {
            const int max = 1000;

            var r = new Random(102);

            for (var i = 0; i < 30; i++)
            {
                var v = new Vector2(r.NextFloat() * max, r.NextFloat() * max);
                var c = v.Floor();
                Assert.AreEqual(Math.Floor(v.X), c.X);
                Assert.AreEqual(Math.Floor(v.Y), c.Y);
            }
        }
开发者ID:wtfcolt,项目名称:game,代码行数:14,代码来源:Vector2Tests.cs

示例9: CeilingTest

        public void CeilingTest()
        {
            const int max = 1000;

            var r = new Random(987);

            for (var i = 0; i < 30; i++)
            {
                var v = new Vector2(r.NextFloat() * max, r.NextFloat() * max);
                var c = v.Ceiling();
                Assert.AreEqual(Math.Ceiling(v.X), c.X);
                Assert.AreEqual(Math.Ceiling(v.Y), c.Y);
            }
        }
开发者ID:wtfcolt,项目名称:game,代码行数:14,代码来源:Vector2Tests.cs

示例10: ResultContentTest

        public void ResultContentTest()
        {
            List<float> data = new List<float>();
            Random rand = new Random();
            data.Add(rand.NextFloat());
            data.Add(rand.NextFloat());
            string[] time = new string[2];
            time[0] = "00:00:02";
            time[1] = "00:00:02";
            Writer.create_result_file(ContentGenerator.generate_result_file_content(data,time));
            string[] testdata = File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), "Data//Result//Result.dat"));
            for (int i = 0; i < testdata.Length; i++)
            {
                Debug.WriteLine(testdata[i]);
            }

            Assert.IsTrue(testdata.Length == 6);
        }
开发者ID:McArren,项目名称:MathNTests,代码行数:18,代码来源:UnitTest1.cs

示例11: Initialize

        public DNA Initialize( Random rand, TaskState task )
        {
            DNA dna = new DNA {
                Shapes = new Shape[task.Shapes]
            };
            int shapesPerSegment = task.Shapes / 9;
            int shapeCounter = 0;

            for( int i = 0; i < task.Shapes - shapesPerSegment * 9; i++ ) {
                Shape shape = new Shape {
                    Color = Color.FromArgb( StartingAlpha, Color.R, Color.G, Color.B ),
                    Points = new PointF[task.Vertices]
                };
                for( int j = 0; j < shape.Points.Length; j++ ) {
                    shape.Points[j] = new PointF( rand.NextFloat( -MaxOverlap, task.ImageWidth + MaxOverlap ),
                                                  rand.NextFloat( -MaxOverlap, task.ImageHeight + MaxOverlap ) );
                }
                dna.Shapes[i] = shape;
                shapeCounter++;
            }

            for( int x = 0; x < 3; x++ ) {
                for( int y = 0; y < 3; y++ ) {
                    for( int i = 0; i < shapesPerSegment; i++ ) {
                        Shape shape = new Shape {
                            Color = Color.FromArgb( StartingAlpha, Color.R, Color.G, Color.B ),
                            Points = new PointF[task.Vertices]
                        };
                        for( int j = 0; j < shape.Points.Length; j++ ) {
                            shape.Points[j] =
                                new PointF(
                                    rand.NextFloat( task.ImageWidth / 3f * x - MaxOverlap,
                                                    task.ImageWidth / 3f * ( x + 1 ) + MaxOverlap ),
                                    rand.NextFloat( task.ImageHeight / 3f * y - MaxOverlap,
                                                    task.ImageHeight / 3f * ( y + 1 ) + MaxOverlap ) );
                        }
                        dna.Shapes[shapeCounter] = shape;
                        shapeCounter++;
                    }
                }
            }
            return dna;
        }
开发者ID:fragmer,项目名称:SuperImageEvolver,代码行数:43,代码来源:SegmentedInitializer.cs

示例12: GenerateHomePositions

        public static void GenerateHomePositions(int n)
        {
            Random rand = new Random();
            bool passed = false;
            Vector2 randPosition = new Vector2(0, 0);

            int i = 0;
            foreach(Team team in TeamManager.teams)
            {
                passed = false;
                while (!passed)
                {
                    randPosition = new Vector2(rand.NextFloat(LevelSpawner.BorderMargin.X + radius, GameRoot.ScreenSize.X - LevelSpawner.BorderMargin.X - 2 * radius), rand.NextFloat(LevelSpawner.BorderMargin.Y + radius, GameRoot.ScreenSize.Y - LevelSpawner.BorderMargin.Y - 2 * radius));
                    if (i == 0)
                    {
                        float distance = Vector2.DistanceSquared(randPosition, GameRoot.ScreenSize * 0.5f);
                        if(distance < (0.5f * GameRoot.ScreenSize.Y * 0.5f * GameRoot.ScreenSize.Y))
                            passed = false;
                        else
                            passed = true;
                    }

                    else
                    {
                        for (int j = 0; j < i; j++)
                        {
                            float distance = Vector2.DistanceSquared(randPosition, TeamManager.teams[j].homePlanet.Position);
                            if (distance < (1.5f * GameRoot.ScreenSize.X / n) * (1.5f * GameRoot.ScreenSize.X / n))
                            {
                                passed = false;
                                break;
                            }
                            else
                                passed = true;
                        }
                    }
                }

                team.homePlanet = new Planet(randPosition, team.Color, 1.0f, i, team);
                team.planetsColonized.Add(team.homePlanet);
                i++;
            }
        }
开发者ID:Crysco,项目名称:Invasion,代码行数:43,代码来源:Team.cs

示例13: MutateShape

 static void MutateShape( Random rand, DNA dna, Shape shape, TaskState task )
 {
     int maxOverlap = task.ProjectOptions.MaxOverlap;
     shape.PreviousState = shape.Clone() as Shape;
     switch( rand.Next( 9 ) ) {
         case 0:
             shape.Color = Color.FromArgb( (byte)rand.Next( task.ProjectOptions.MinAlpha, 256 ), shape.Color.R,
                                           shape.Color.G, shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 1:
             shape.Color = Color.FromArgb( shape.Color.A, (byte)rand.Next( 256 ), shape.Color.G, shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 2:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, (byte)rand.Next( 256 ), shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 3:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, shape.Color.G, (byte)rand.Next( 256 ) );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 4:
         case 5:
             shape.Points[rand.Next( shape.Points.Length )].X = rand.NextFloat( -maxOverlap,
                                                                                task.ImageWidth + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoint;
             break;
         case 6:
         case 7:
             shape.Points[rand.Next( shape.Points.Length )].Y = rand.NextFloat( -maxOverlap,
                                                                                task.ImageHeight + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoint;
             break;
         case 8:
             shape.Points[rand.Next( shape.Points.Length )].X = rand.NextFloat( -maxOverlap,
                                                                                task.ImageWidth + maxOverlap );
             shape.Points[rand.Next( shape.Points.Length )].Y = rand.NextFloat( -maxOverlap,
                                                                                task.ImageHeight + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoints;
             break;
     }
 }
开发者ID:fragmer,项目名称:SuperImageEvolver,代码行数:43,代码来源:MediumMutator.cs

示例14: Box

        public Box(int _screenW, int _screenH, Random _rndRandom)
            : base()
        {
            screenW = _screenW;
              screenH = _screenH;

              rnd = _rndRandom;

              x = randomBetween(0, screenW);
              y = randomBetween(0, screenH);
              width = randomBetween(10, 50);
              height = randomBetween(10, 50);
              speed = randomBetween(50, 250);
              dirX = rnd.NextFloat() < 0.5d ? -1 : 1;
              dirY = rnd.NextFloat() < 0.5d ? -1 : 1;

              aabb = new AABB();
              updateAABB();
        }
开发者ID:DoctorB,项目名称:spatial-hash,代码行数:19,代码来源:Box.cs

示例15: StratifiedSample1D

 /// <summary>
 /// Given nx strata in [0,1],
 /// Place a sample in each one,
 /// starting from samples[ offset ]
 /// and ending at samples[ offset + nx - 1 ]
 /// </summary>
 /// <param name="samples"></param>
 /// <param name="jitter"></param>
 public static void StratifiedSample1D( float[] samples,
     int offset, int nx,
     bool jitter, Random random )
 {
     float invTot = 1.0f / nx;
     for( int i = 0; i < nx; ++i )
     {
         float j = jitter ? random.NextFloat() : 0.5f;
         samples[ offset + i ] = ( i + j ) * invTot;
     }
 }
开发者ID:jiawen,项目名称:libcgt.net,代码行数:19,代码来源:SamplingUtils.cs


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