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


C# Random.NextGaussian方法代码示例

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


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

示例1: Driver

        private static void Driver(
			double averageRequestSize,
			double standardDeviation,
			Random random,
			int simulationSteps,
			int memorySize,
			AllocationStrategy strategy,
			out double averageSearchTime,
			out double averageMemoryUtilization)
        {
            // Setup driver.
            var mm = new MemoryManager(memorySize, strategy);
            var reserved = new List<Allocation>();

            // Statistics
            long totalHolesExamined = 0;
            double totalMemoryUtilization = 0;

            for (int i = 0; i < simulationSteps; i++)
            {
                int requestSize = random.NextGaussian(averageRequestSize, standardDeviation, 1, memorySize);
                int allocationAddr, holesExamined;
                Allocation alloc;
                while (mm.Request(requestSize, out allocationAddr, out holesExamined))
                {
                    reserved.Add(alloc = new Allocation(allocationAddr, requestSize));
                    int placeToSwap = random.Next(reserved.Count);
                    reserved[reserved.Count - 1] = reserved[placeToSwap];
                    reserved[placeToSwap] = alloc;
                    totalHolesExamined += holesExamined;
                    requestSize = random.NextGaussian(averageRequestSize, standardDeviation, 1, memorySize);
                }
                // Count holes examined by failed request.
                totalHolesExamined += holesExamined;
                // Record memory utilization.
                totalMemoryUtilization += reserved.Sum(allocation => allocation.Size) / (double)memorySize;
                // Release a random reserved segment. Because the reserved list
                // is randomly ordered, we simply (and efficiently) remove the
                // last element.
                if(reserved.Count > 0)
                {
                    mm.Release(reserved[reserved.Count - 1].Address);
                    reserved.RemoveAt(reserved.Count - 1);
                }
            }

            averageSearchTime = totalHolesExamined / (double) simulationSteps;
            averageMemoryUtilization = totalMemoryUtilization / simulationSteps;
        }
开发者ID:EkardNT,项目名称:CS143B,代码行数:49,代码来源:Program.cs

示例2: CreateRandomObjective

        public static Objective CreateRandomObjective(int index)
        {
            // generate name
            var name = $"Objective {index + 1}";

            // generate contribution
            var random = new Random(index);
            var contributionCount = random.Next(10, 100);
            var contributions = new List<ObjectiveContribution>();
            var mean = 3;
            var std = 5;
            for (int i = 0; i < contributionCount; i++)
            {
                contributions.Add(new ObjectiveContribution
                {
                    Timestamp = DateTime.Today.AddDays(i - contributionCount + 1),
                    Count = (int)Math.Round(Math.Max(random.NextGaussian(mean, std), 0))
                });
            }

            // generate icon string
            var iconName = GetRandomImageName(random);

            // generate color string
            string colorString = CreateRandomColor(random);

            // generate default span
            var defaultRowSpan = 1;
            var defaultColumnSpan = (new int[] { 1, 2, 5 }).Contains(index) ? 2 : 1;

            return new Objective { Name = name, Contributions = contributions, IconName = iconName, ColorString = colorString, RowSpan = defaultRowSpan, ColumnSpan = defaultColumnSpan };
        }
开发者ID:ShiroYacha,项目名称:Planact,代码行数:32,代码来源:Factory.cs

示例3: Galaxy

 public Galaxy(Random random)
 {
     int number = 1 + (int)Math.Abs(random.NextGaussian(0, 1000));
     Systems = new List<CelestialSystem>(number);
     for (int i = 0; i < number; i++)
     {
         CelestialSystem system = new CelestialSystem(random);
         Systems.Add(system);
     }
 }
开发者ID:VilRan,项目名称:TTOS0200-Assignments,代码行数:10,代码来源:Universe.cs

示例4: Universe

 public Universe(Random random)
 {
     int number = 1 + (int)Math.Abs(random.NextGaussian(0, 10));
     Galaxies = new List<Galaxy>(number);
     for (int i = 0; i < number; i++)
     {
         Galaxy galaxy = new Galaxy(random);
         Galaxies.Add(galaxy);
     }
 }
开发者ID:VilRan,项目名称:TTOS0200-Assignments,代码行数:10,代码来源:Universe.cs

示例5: Game

    public Game()
    {
      ResetToDefault();
      ratioD = d2 / d1;

      pixel_painter = new PixelPainter();
      sprite_painter = new SpritePainter();
      painter = sprite_painter;

      rnd = new Random((int) DateTime.Now.ToBinary());
      random_numbers = new double[asteriks_count_max];
      for (var i = 0; i < asteriks_count_max; i++) random_numbers[i] = (rnd.NextGaussian(rnd.Next(-100, 100), 100 / 2));

      render = new Thread(Render){ IsBackground = true };
    }
开发者ID:andykras,项目名称:Luke-StarWalker,代码行数:15,代码来源:Game.cs

示例6: GenerateData

 /// <summary>
 /// 引数に与えられた標準偏差を持つガウスノイズを加えられた<br />
 /// sin 関数一周期分のデータを、引数に与えられた個数生成する。
 /// </summary>
 /// <param name="length">データ長。</param>
 /// <param name="deviation">標準偏差。</param>
 public static double[] GenerateData(int length, double deviation)
 {
     Random rnd = new Random();
     var data = new double[length];
     for (int i = 0; i < length; i++)
         data[i] = Math.Sin(2 * Math.PI / length * i) + deviation * rnd.NextGaussian();
     return data;
 }
开发者ID:y-takashina,项目名称:RegressionDemo,代码行数:14,代码来源:Regression.cs

示例7: Main

        public static void Main(String[] args)
        {
            Random random = new Random();
            int length = 100;
            double[] A = new double[length];
            double[] B = new double[length];
            double aAvg = 70.0;
            double bAvg = 70.5;
            for (int i = 0; i < length; i++)
            {
                A[i] = aAvg + random.NextGaussian();
                B[i] = bAvg + random.NextGaussian();
            }

            Console.Out.WriteLine(@"A has length " + A.Length + @" and mean " + Mean(A));
            Console.Out.WriteLine(@"B has length " + B.Length + @" and mean " + Mean(B));
            for (int t = 0; t < 10; t++)
            {
                Console.Out.WriteLine(@"p-value: " + SigLevelByApproxRand(A, B));
            }
        }
开发者ID:sandily,项目名称:Stanford.NER.Net,代码行数:21,代码来源:ArrayMath.cs

示例8: CelestialBody

        public CelestialBody(Random random, double mass)
        {
            Mass = mass;

            int numSatellites = 0;
            if ( !(this is Asteroid))
                do
                    numSatellites = (int)Math.Abs(random.NextGaussian(0, 10));
                while (numSatellites > 10);

            Satellites = new List<CelestialBody>(numSatellites);
            for (int i = 0; i < numSatellites; i++)
            {
                double massFraction, semimajorAxis, eccentricity;
                do
                    massFraction = Math.Abs(random.NextGaussian(0, 0.001));
                while (massFraction > 0.01);
                do
                    semimajorAxis = Math.Abs(random.NextGaussian(0, SphereOfInfluence / 10));
                while (semimajorAxis > SphereOfInfluence);
                do
                    eccentricity = Math.Abs(random.NextGaussian(0, 0.1));
                while (eccentricity > 1);

                CelestialBody satellite = CreateFromMass(Mass * massFraction, random);
                satellite.Primary = this;
                satellite.SetOrbit(semimajorAxis, eccentricity);
                Satellites.Add(satellite);
            }
        }
开发者ID:VilRan,项目名称:TTOS0200-Assignments,代码行数:30,代码来源:Universe.cs


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