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