예제 #1
0
    public DungeonRoom AddStartingRoom()
    {
        var width  = Rand.NextGaussian(RoomWidthMean, RoomWidthStd);
        var height = Rand.NextGaussian(RoomHeightMean, RoomHeightStd);

        var room = new DungeonRoom(0, Level, new Vector2Int(0, 0), width, height);

        Rooms.Add(room);

        return(room);
    }
예제 #2
0
파일: Program.cs 프로젝트: EkardNT/CS143B
        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;
        }
        protected float GetRotateMagnitudeWithNoise(Vector3 rotation, float noise)
        {
            System.Random random        = new System.Random();
            float         internalNoise = applyActionNoise ? (float)random.NextGaussian(rotateGaussianMu, rotateGaussianSigma) : 0;

            return(rotation.y + noise + (float)internalNoise);
        }
        protected float GetMoveMagnitudeWithNoise(ServerAction action)
        {
            System.Random random        = new System.Random();
            float         internalNoise = applyActionNoise ? (float)random.NextGaussian(movementGaussianMu, movementGaussianSigma) : 0;

            return(action.moveMagnitude + action.noise + (float)internalNoise);
        }
예제 #5
0
        private float GetRotateMagnitudeWithNoise(ServerAction action)
        {
            var random = new System.Random();
            var noise  = applyActionNoise ? random.NextGaussian(rotateGaussianMu, rotateGaussianSigma) : 0;

            return(action.rotation.y + action.noise + (float)noise);
        }
예제 #6
0
        public override object Invoke(object[] args)
        {
            if (args == null || args.Length != 2)
            {
                return(null);
            }

            if (args[0] == null || args[1] == null)
            {
                return(null);
            }

            try
            {
                double mu    = Convert.ToDouble(args[0]);
                double sigma = Convert.ToDouble(args[1]);

                if (double.IsNaN(mu) || double.IsNaN(sigma))
                {
                    return(null);
                }

                lock (_Random)
                {
                    double result = _Random.NextGaussian(mu, sigma);
                    return(result);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #7
0
        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 };
        }
예제 #8
0
        private float GetMoveMagnitudeWithNoise(ServerAction action)
        {
            var random = new System.Random();
            var noise  = applyActionNoise ? random.NextGaussian(movementGaussianMu, movementGaussianSigma) : 0;

            return(action.moveMagnitude + action.noise + (float)noise);
        }
예제 #9
0
        void FixedUpdate()
        {
            //when in drone mode, automatically pause time and physics simulation here
            //time and physics will continue once emitFrame is called
            //Note: this is to keep drone and object movement in sync, as pausing just object physics would
            //still allow the drone's character controller Move() to function in "real time" and we dont have
            //support for fully continuous drone movement and emitFrame metadata generation at the same time.

            //NOTE/XXX: because of the fixedupdate/lateupdate/delayed coroutine emitframe nonsense going on
            //here, the in-editor axisAlignedBoundingBox metadata for drone objects seems to be offset by some number of updates.
            //it's unclear whether this is only an in-editor debug draw issue, or the actual metadata for the axis
            //aligned box is messed up, but yeah.

            if (hasFixedUpdateHappened)
            {
                Time.timeScale         = 0;
                Physics.autoSimulation = false;
                physicsSceneManager.physicsSimulationPaused = true;
            }
            else
            {
                fixupdateCnt++;
                hasFixedUpdateHappened = true;
            }

            if (thrust.magnitude > 0.0001 && Time.timeScale != 0)
            {
                if (dronePositionRandomNoiseSigma > 0)
                {
                    var     random = new System.Random();
                    var     noiseX = (float)random.NextGaussian(0.0f, dronePositionRandomNoiseSigma / 3.0f);
                    var     noiseY = (float)random.NextGaussian(0.0f, dronePositionRandomNoiseSigma / 3.0f);
                    var     noiseZ = (float)random.NextGaussian(0.0f, dronePositionRandomNoiseSigma / 3.0f);
                    Vector3 noise  = new Vector3(noiseX, noiseY, noiseZ);
                    m_CharacterController.Move((thrust * Time.fixedDeltaTime) + noise);
                }
                else
                {
                    m_CharacterController.Move(thrust * Time.fixedDeltaTime);
                }
            }

            if (this.agentState == AgentState.PendingFixedUpdate)
            {
                this.agentState = AgentState.ActionComplete;
            }
        }
예제 #10
0
 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);
     }
 }
예제 #11
0
 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);
     }
 }
예제 #12
0
    public DungeonFloor GenerateFloor()
    {
        var level = Level + 1;

        var floor = new DungeonFloor(level);

        Floors.Add(floor);

        var numRooms = Rand.NextGaussian(RoomsMean, RoomsStd);

        Debug.Log($"Generating Floor {level} with {numRooms} rooms.");

        return(floor.GenerateFloor(numRooms));
    }
예제 #13
0
    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 };
    }
예제 #14
0
    void Start()
    {
        m_GaussianRandom = new System.Random(UnityEngine.Random.Range(0, 10000));

        float maxRand = 0;
        float minRand = 0;

        for (int i = 0; i < NUM_SAMPLES; i++)
        {
            var rand = m_GaussianRandom.NextGaussian();

            maxRand = Mathf.Max((float)rand, (float)maxRand);
            minRand = Mathf.Min((float)rand, (float)minRand);
        }

        Debug.Log("Generated " + NUM_SAMPLES + " of random gaussian numers. Max: " + maxRand + " Min " + minRand);
    }
예제 #15
0
        public override void MoveRelative(ServerAction action)
        {
            if (!allowHorizontalMovement && Math.Abs(action.x) > 0)
            {
                throw new InvalidOperationException("Controller does not support horizontal movement. Set AllowHorizontalMovement to true on the Controller.");
            }
            var moveLocal     = new Vector3(action.x, 0, action.z);
            var moveMagnitude = moveLocal.magnitude;

            if (moveMagnitude > 0.00001)
            {
                //random.NextGaussian(RotateGaussianMu, RotateGaussianSigma);
                var random = new System.Random();


                // rotate a small amount with every movement since robot doesn't always move perfectly straight
                if (this.applyActionNoise)
                {
                    var rotateNoise = (float)random.NextGaussian(rotateGaussianMu, rotateGaussianSigma / 2.0f);
                    transform.rotation = transform.rotation * Quaternion.Euler(new Vector3(0.0f, rotateNoise, 0.0f));
                }
                var moveLocalNorm = moveLocal / moveMagnitude;
                if (action.moveMagnitude > 0.0)
                {
                    action.moveMagnitude = moveMagnitude * action.moveMagnitude;
                }
                else
                {
                    action.moveMagnitude = moveMagnitude * gridSize;
                }

                var magnitudeWithNoise = GetMoveMagnitudeWithNoise(action);

                actionFinished(moveInDirection(
                                   this.transform.rotation * (moveLocalNorm * magnitudeWithNoise),
                                   action.objectId,
                                   action.maxAgentsDistance,
                                   action.forceAction
                                   ));
            }
            else
            {
                actionFinished(false);
            }
        }
예제 #16
0
        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);
            }
        }
예제 #17
0
        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));
            }
        }
예제 #18
0
 public static double NextGaussian(double mu = 0, double sigma = 1)
 {
     return(random.NextGaussian(mu, sigma));
 }
예제 #19
0
 /// <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;
 }