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


C# System.Random.NextDouble方法代码示例

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


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

示例1: Equals_GetHashCode_Contract

        public void Equals_GetHashCode_Contract()
        {
            var rnd = new System.Random();
            var offset = rnd.NextDouble() * 60;
            if (rnd.NextDouble() < 0.5)
            {
                offset *= -1;
            }

            var left = new MultiPoint(GetPoints(offset));
            var right = new MultiPoint(GetPoints(offset));

            Assert.AreEqual(left, right);
            Assert.AreEqual(right, left);

            Assert.IsTrue(left.Equals(right));
            Assert.IsTrue(left.Equals(left));
            Assert.IsTrue(right.Equals(left));
            Assert.IsTrue(right.Equals(right));

            Assert.IsTrue(left == right);
            Assert.IsTrue(right == left);

            Assert.AreEqual(left.GetHashCode(), right.GetHashCode());
        }
开发者ID:GeoJSON-Net,项目名称:GeoJSON.Net,代码行数:25,代码来源:MultiPointTests.cs

示例2: Equals_GetHashCode_Contract

        public void Equals_GetHashCode_Contract()
        {
            var rnd = new System.Random();
            var offset = rnd.NextDouble() * 60;
            if (rnd.NextDouble() < 0.5)
            {
                offset *= -1;
            }

            var leftLine = new List<LineString>();
            leftLine.Add(GetLineString(offset + 1));
            leftLine.Add(GetLineString(offset + 2));

            var left = new MultiLineString(leftLine);

            var rightLine = new List<LineString>();
            rightLine.Add(GetLineString(offset + 1));
            rightLine.Add(GetLineString(offset + 2));

            var right = new MultiLineString(rightLine);

            Assert.AreEqual(left, right);
            Assert.AreEqual(right, left);

            Assert.IsTrue(left.Equals(right));
            Assert.IsTrue(left.Equals(left));
            Assert.IsTrue(right.Equals(left));
            Assert.IsTrue(right.Equals(right));

            Assert.IsTrue(left == right);
            Assert.IsTrue(right == left);

            Assert.AreEqual(left.GetHashCode(), right.GetHashCode());
        }
开发者ID:GeoJSON-Net,项目名称:GeoJSON.Net,代码行数:34,代码来源:MultiLineStringTests.cs

示例3: Przetwarzaj

        public override void Przetwarzaj(IMapa mapa)
        {
            _rand = new Random(_parametryPerlina.Ziarno);
             var przesuniecieX = (float)_rand.NextDouble() * 4096f;
             var przesuniecieZ = (float)_rand.NextDouble() * 4096f;
             float wspolczynnik = 1f;
             for (int warstwa = 2; warstwa <= _parametryPerlina.IloscWarstw; ++warstwa)
             {
            wspolczynnik += Mathf.Pow(_parametryPerlina.ZachowanieSkali, warstwa);
            }
             float znormalizowanaSkalaPoczatkowa = _parametryPerlina.Skala/wspolczynnik;

             foreach (IPunkt punkt in mapa.Punkty)
             {
            float wysokosc = 0;
            for (int warstwa = 0; warstwa < _parametryPerlina.IloscWarstw; ++warstwa)
            {
               float gestosc = _parametryPerlina.Gestosc * Mathf.Pow(_parametryPerlina.SkokGestosci, warstwa); // rosnie
               float skala = znormalizowanaSkalaPoczatkowa * Mathf.Pow(_parametryPerlina.ZachowanieSkali, warstwa); // maleje
               wysokosc += Mathf.PerlinNoise((punkt.Pozycja.x + przesuniecieX) * gestosc,
                                             (punkt.Pozycja.z + przesuniecieZ) * gestosc)
                                                      *skala;
            }
            punkt.Wysokosc = wysokosc;
             }
        }
开发者ID:pslusarczyk,项目名称:praca_magisterska,代码行数:26,代码来源:ModyfikatorWysokosciPerlinem.cs

示例4: BuildSurfaceMesh

        public static void BuildSurfaceMesh(ref MeshPlane mesh, ref Random rand)
        {
            var brush = Resources.Load("PlanetBuilding/SurfaceBrush");

            if (brush == null)
            {
                Debug.LogError("Unable to load basic brush prefab");
                return;
            }

            var rampTex = Resources.Load("Textures/PlanetRamp") as Texture;

            if (rampTex == null)
            {
                Debug.LogError("Unable to load planet colour ramp");
                return;
            }

            // Apply brush texture somehow
            // * 0.1f
            float brushBaseSize = 1.0f;
            float brushSizeLarge = brushBaseSize * 0.2f;
            float brushSizeSmall = brushBaseSize * 0.02f;

            for (int i = 0; i < rand.Next(25, 75); ++i)
            {
                var go = (GameObject.Instantiate(brush) as GameObject);

                var ch = go.transform.GetChild(0);
                var brushScale = (float)(brushSizeSmall + (rand.NextDouble() * brushSizeLarge));
                ch.localScale = new Vector3(brushScale, brushScale, brushScale);

                go.transform.SetParent(mesh.transform);
                go.transform.Rotate(
                    (float)rand.NextDouble() * 360.0f,
                    (float)rand.NextDouble() * 360.0f,
                    (float)rand.NextDouble() * 360.0f
                    );
            }

            var localCam = mesh.gameObject.AddComponent<Camera>();
            localCam.cullingMask = PlanetBrushLayer;
            localCam.fieldOfView = 90;
            localCam.backgroundColor = Color.black;

            Cubemap c = new Cubemap(2048, TextureFormat.ARGB32, false);
            localCam.RenderToCubemap(c);

            mesh.GetComponent<Renderer>().material.SetTexture("_Tex", c);
            mesh.GetComponent<Renderer>().material.SetTexture("_PlanetRamp", rampTex);

            Component.Destroy(localCam);
             			foreach ( Transform ch in mesh.transform ){
             				GameObject.Destroy(ch.gameObject);
             			}
        }
开发者ID:finlaybob,项目名称:odyssey2,代码行数:56,代码来源:PlanetFactory.cs

示例5: Generate

        public Model Generate()
        {
            int count = 1000;
            Vector3[] v = new Vector3[count];
            Vector3[] r = new Vector3[count];
            Random random = new Random();
            Color[] color = new Color[count];
            float[] m = new float[count];

            v[0] = new Vector3(0,
                    0,
                    0);
            r[0] = new Vector3(0,
                0,
                0);
            m[0] = 1000000000;
            color[0] = Color.white;

            for (int i = 1; i < count; i++)
            {
                v[i] = new Vector3((float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1),
                    (float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1),
                    (float)random.NextDouble() * (random.NextDouble() > 0.5 ? 1 : -1));
                r[i] = new Vector3((float)random.NextDouble() * 100,
                    (float)random.NextDouble() * 100,
                    (float)random.NextDouble() * 100);
                m[i] = random.Next(10000, 100000);
                color[i] = Color.yellow;
            }
            Model model = new Model(r, v, m, color);
            model.G = 0.00001f;
            model.dt = 0.005f;
            return model;
        }
开发者ID:anfulu36484,项目名称:GravitatioanlSimulation,代码行数:34,代码来源:ModelGenerator2.cs

示例6: CalculateMeanAndVarianceTest

    public void CalculateMeanAndVarianceTest() {
      System.Random random = new System.Random(31415);

      int n = testData.GetLength(0);
      int cols = testData.GetLength(1);
      {
        for (int col = 0; col < cols; col++) {
          double scale = random.NextDouble();
          IEnumerable<double> x = from rows in Enumerable.Range(0, n)
                                  select testData[rows, col] * scale;
          double[] xs = x.ToArray();
          double mean_alglib, variance_alglib;
          mean_alglib = variance_alglib = 0.0;
          double tmp = 0;

          alglib.samplemoments(xs, n, out  mean_alglib, out variance_alglib, out tmp, out tmp);

          var calculator = new OnlineMeanAndVarianceCalculator();
          for (int i = 0; i < n; i++) {
            calculator.Add(xs[i]);
          }
          double mean = calculator.Mean;
          double variance = calculator.Variance;

          Assert.IsTrue(mean_alglib.IsAlmost(mean));
          Assert.IsTrue(variance_alglib.IsAlmost(variance));
        }
      }
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:29,代码来源:StatisticCalculatorsTest.cs

示例7: SpawnBalls

        void SpawnBalls()
        {
            //clean trailrenderers
            StartCoroutine(greenBall.TrailRenderDestroy());
            StartCoroutine(yellowBall.TrailRenderDestroy());

            //randomize balls & set directions
            System.Random rand = new System.Random();
            bool randomBool = rand.NextDouble() >= 0.5;
            if(previousBool==randomBool){ //prevent randomizing the same value too many times
                consecutiveBools++;
            } else {
                consecutiveBools = 0;
            }

            if(randomBool && consecutiveBools < 3){
                greenBall.transform.position = topSpawn.transform.position;
                greenBall.isGoingUp = false;
                yellowBall.transform.position = bottomSpawn.transform.position;
                yellowBall.isGoingUp = true;
            } else {
                greenBall.transform.position = bottomSpawn.transform.position;
                greenBall.isGoingUp = true;
                yellowBall.transform.position = topSpawn.transform.position;
                yellowBall.isGoingUp = false;
            }
            previousBool = randomBool;
        }
开发者ID:loloop,项目名称:videogames-moveis,代码行数:28,代码来源:GameStateManager.cs

示例8: PlanetNoisePerlin

		public PlanetNoisePerlin( int seed )
		{
			System.Random rnd = new System.Random( seed );

			grad		= new Vector3[ 12 ];
			grad[  0 ]	= new Vector3(  1,  1,  0 );
			grad[  1 ]	= new Vector3( -1,  1,  0 );
			grad[  2 ]	= new Vector3(  1, -1,  0 );
			grad[  3 ]	= new Vector3( -1, -1,  0 );
			grad[  4 ]	= new Vector3(  1,  0,  1 );
			grad[  5 ]	= new Vector3( -1,  0,  1 );
			grad[  6 ]	= new Vector3(  1,  0, -1 );
			grad[  7 ]	= new Vector3( -1,  0, -1 );
			grad[  8 ]	= new Vector3(  0,  1,  1 );
			grad[  9 ]	= new Vector3(  0, -1,  1 );
			grad[ 10 ]	= new Vector3(  0,  1, -1 );
			grad[ 11 ]	= new Vector3(  0, -1, -1 );

			perm = new uint[ permStride ];

			for( int i = 0; i < permStride / 2; ++i )
				perm[ i ] = ( uint ) Mathf.FloorToInt( ( float ) rnd.NextDouble() * ( permStride / 2 ) );

			for( int i = permStride / 2; i < permStride; ++i )
				perm[ i ] = perm[ i & ( permStride / 2 - 1 ) ];
		}
开发者ID:blairm,项目名称:PlanetTextureGeneratorUnity,代码行数:26,代码来源:PlanetNoisePerlin.cs

示例9: getCellNoise

 public static float[,] getCellNoise(int height, int width,int seed,int featurePointCount)
 {
     noisePrng = new System.Random(seed);
     float[,] noise = new float[height,width];
     Vector2[] featurePoints = new Vector2[featurePointCount];
     for(int i =0; i < featurePointCount;i++)
     {
         featurePoints[i] = new Vector2((float)noisePrng.NextDouble(),(float)noisePrng.NextDouble());
     }
     for(int y =0; y < height; y++)
     {
         for(int x =0; x < height; x++)
         {
             noise[x,y] = setCell(featurePoints,x,y,height,width);
         }
     }
     return noise;
 }
开发者ID:billy1234,项目名称:TerrainGenMaster,代码行数:18,代码来源:NoiseExtentionLib.cs

示例10: RandomNumGen

        public RandomNumGen(int seed)
        {
            Rand = new System.Random(seed);

            rand_num_ = new List<double>(Environment.mazeSize_ * Environment.mazeSize_ * Evaluator.LIFE_TIME);
            for (int i=0; i<rand_num_.Capacity; i++)
            {
                rand_num_.Add(Rand.NextDouble());
            }
            index_ = 0;
        }
开发者ID:Troilk,项目名称:VacuumCleaner,代码行数:11,代码来源:RandomNumGen.cs

示例11: CreateColorFromStringHash

        /// <summary>
        /// Selects a random, non-red color based on the hashcode of a string
        /// </summary>
        /// <param name="stringValue">A string to be used as a seed for the random color</param>
        /// <returns>A random color based on the input string</returns>
        public static Color CreateColorFromStringHash(string stringValue)
        {
            var color = Color.Yellow;
            if (!string.IsNullOrEmpty(stringValue))
            {
                // Build random vector representing rgb color based on username
                var randSeed = stringValue.GetHashCode();
                var rand = new System.Random(randSeed);
                var colorVector = new Vector3D((float)rand.NextDouble(), (float)rand.NextDouble(), (float)rand.NextDouble());

                // Keep the color (vector) from being too close to red (x) so it doesn't conflict with the selection color
                if (colorVector.Y > colorVector.Z)
                {
                    if (colorVector.X > colorVector.Y)
                        colorVector = new Vector3D(colorVector.Z, colorVector.Y, colorVector.Z);
                }
                else if (colorVector.Z > colorVector.Y)
                {
                    if (colorVector.X > colorVector.Z)
                        colorVector = new Vector3D(colorVector.Y, colorVector.Y, colorVector.Z);
                }

                // Make sure color isn't too dark
                if (colorVector.Magnitude < 1f)
                    colorVector *= (1f / colorVector.Magnitude);

                // Make sure color components stay within bounds
                if (colorVector.X > 1)
                    colorVector = new Vector3D(1f, colorVector.Y, colorVector.Z);
                if (colorVector.Y > 1)
                    colorVector = new Vector3D(colorVector.X, 1f, colorVector.Z);
                if (colorVector.Z > 1)
                    colorVector = new Vector3D(colorVector.X, colorVector.Y, 1f);

                color = Color.FromArgb(255, (int)(colorVector.X * 255), (int)(colorVector.Y * 255), (int)(colorVector.Z * 255));
            }

            return color;
        }
开发者ID:CuriousX,项目名称:annotation-and-image-markup,代码行数:44,代码来源:AimSettings.cs

示例12: GenerateNoise

 private static float[,] GenerateNoise(int Seed, int Width, int Height)
 {
     float[,] Noise = new float[Width, Height];
     System.Random RandomGenerator = new System.Random(Seed);
     for (int x = 0; x < Width; ++x)
     {
         for (int y = 0; y < Height; ++y)
         {
             Noise[x, y] = ((float)(RandomGenerator.NextDouble()) - 0.5f) * 2.0f;
         }
     }
     return Noise;
 }
开发者ID:MarkWalls,项目名称:Craig-s-Utility-Library,代码行数:13,代码来源:PerlinNoise.cs

示例13: MenuGenerate

        IEnumerator MenuGenerate()
        {
            yield return new WaitForSeconds(2f);

            System.Random rng = new System.Random();
            if (RandomGeneration)
            {
                GridSeed = Random.Range(1, int.MaxValue);
                MaxObstacleHeight = Random.Range(1.5f, 4);
                ObstacleColorA = new Color((float)rng.NextDouble(), (float)rng.NextDouble(), (float)rng.NextDouble());
            }

            foreach (Transform obstacle in Obstacles)
            {
                DestroyImmediate(obstacle.gameObject);
                yield return new WaitForSeconds(0.02f);
            }
            Obstacles.Clear();

            yield return new WaitForSeconds(2f);

            shuffledNodeCoords = new Queue<Coord>(Functions.ShuffleArray(allNodeCoords.ToArray(), GridSeed));
            bool[,] obstacleMap = new bool[GridSizeX, GridSizeY];
            int currentObstacleCount = 0;

            for (int i = 0; i < Nodes.Count * ObstaclePercent; i++)
            {
                Coord randomCoord = GetRandomCoord();
                Vector3 coordPos = CoordToVector(randomCoord.X, randomCoord.Y);
                obstacleMap[randomCoord.X, randomCoord.Y] = true;
                currentObstacleCount++;

                if (coordPos != GridCenter && GridIsFullyAccessible(obstacleMap, currentObstacleCount))
                {
                    Transform obstacle = (Transform)Instantiate(Obstacle, coordPos, Quaternion.identity);
                    obstacle.parent = transform;

                    float obstacleHeight = Mathf.Lerp(MinObstacleHeight,MaxObstacleHeight , (float)rng.NextDouble());
                    obstacle.localScale = new Vector3(obstacle.localScale.x, obstacleHeight, obstacle.localScale.z);
                    obstacle.position += new Vector3(0, obstacle.localScale.y / 2, 0);

                    Renderer obstacleRenderer = obstacle.GetComponent<Renderer>();
                    Material obstacleMaterial = new Material(obstacleRenderer.sharedMaterial);
                    float colorPercent = randomCoord.Y / (float)GridSizeY;
                    obstacleMaterial.color = Color.Lerp(ObstacleColorA, ObstacleColorB, colorPercent);
                    obstacleRenderer.sharedMaterial = obstacleMaterial;

                    Obstacles.Add(obstacle);

                }
                else
                {
                    obstacleMap[randomCoord.X, randomCoord.Y] = false;
                    currentObstacleCount--;
                }
                yield return new WaitForSeconds(0.02f);
            }
        }
开发者ID:AkuKuylaars,项目名称:Blocklands,代码行数:58,代码来源:Grid.cs

示例14: Start

		IEnumerator Start()
		{
			pauseUser = false;
			pauseWait = true;
			enabled = false;
			Debug.Log("World begin start");
			// if no pools wait for them.
			if (!PoolBase.Instance)
			{
				Debug.Log("Waiting for PoolBase instance.");
				while (!PoolBase.Instance)
				{
					yield return null;
				}
			}
			// wait for UI.
			yield return StartCoroutine(UIBase.WaitInstance());

			UserEnergy = TotalUserEnergy;

			Random = new System.Random(Startup.Seed);

			sizeX = (int)transform.localScale.x;
			sizeXhalf = sizeX / 2;
			sizeZ = (int)transform.localScale.z;
			sizeZhalf = sizeZ / 2;
			if ((float)sizeX != transform.localScale.x || (float)sizeZ != transform.localScale.z)
			{
				Debug.LogWarning("World local scale should be a interger.");
			}

			// get pools
			PoolBase pools = PoolBase.Instance;
			cubers = pools.Cubers;
			fourths = pools.Fourths;
			energys = pools.Energys;


			// spawn cubers
			int infected = 0;
			if (Startup.PrecentInfected > 0)
			{
				infected = (int)((float)Startup.Cubers * ((float)Startup.PrecentInfected / 100f));
				if (infected <= 0)
					infected = 1;
			}
			for (int i = 0; i < Startup.Cubers; ++i)
			{
				Vector3 position;
				if (FindGround(new Ray(transform.position + new Vector3(-sizeXhalf + Random.Next(sizeX), 100f, -sizeZhalf + Random.Next(sizeZ)), Vector3.down), out position))
				{
					cubers.Pull().Init(position, --infected >= 0, 0.5f + (float)Random.NextDouble() * 0.6f);//, Color.black);
				}
			}

			// startup energy
			for (int i = 0; i < EnergyCount; ++i)
			{
				NewEnergy(EnergyMin, EnergyMax);
			}
			enabled = true;
			pauseWait = false;
			Debug.Log("World end start");
		}
开发者ID:RaymondEllis,项目名称:ViralCubers,代码行数:64,代码来源:World.cs

示例15: SetComponents

        private void SetComponents()
        {
            this.Camera = new Camera(this, Vector3.UnitZ * 400, -Vector3.UnitZ);
            this.World = new InfinityWorld(this);
            this.World.WorldObjects.Add(new Characters.ZombieCharacter(this, new Vector3(-95, 0, 0), Color.Yellow));
            var rnd = new System.Random();

            for (int i = 0; i < 16; i++)
            {
                var z = new Characters.ZombieCharacter(this, new Vector3(rnd.Next(0, 300) * (float)rnd.NextDouble() * (rnd.Next() % 2 == 0 ? -1 : 1), rnd.Next(0, 300) * (float)rnd.NextDouble() * (rnd.Next() % 2 == 0 ? -1 : 1), 0), Color.Red);
                z.OrientationScalar = rnd.Next(-3, 3) + (float)rnd.NextDouble();
                this.World.WorldObjects.Add(z);
            }

            this.World.WorldObjects.Add(new Characters.HumanCharacter(this, new Vector3(0, 5, 0)));
            //this.World.Humans.Add(new Characters.HumanCharacter(this, new Vector3(-66, 45, 0)));
        }
开发者ID:Dani88,项目名称:Zombies,代码行数:17,代码来源:Game.cs


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