public void CmdSetClientsRandomValues()
    {
        LocalRandom rand = FindObjectOfType <LocalRandom>();

        float[] arr = rand.GetRandomValues();
        RpcSetClientsRandomValues(arr);
    }
Пример #2
0
            public override float NextSingle()
            {
                float result = LocalRandom.NextSingle();

                AssertInRange(result);
                return(result);
            }
Пример #3
0
            public override int Next()
            {
                int result = LocalRandom.Next();

                AssertInRange(result, 0, int.MaxValue);
                return(result);
            }
Пример #4
0
        /// <summary>
        /// Override to the string method to display the citation in a pretty mannor.
        /// </summary>
        /// <returns>Stylized string of the citation.</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("====================================== Citation " + LocalRandom.GetRandomNumber(0, 10000).ToString() + "  =======================================\r\n");
            sb.AppendLine();
            sb.AppendFormat("Officer: {0} {1} {2} ({3})\r\n", OfficerRank, OfficerFirstName, OfficerLastName, OfficerBadgeId.ToString());
            sb.AppendLine("============================================================================================\r\n");
            sb.AppendFormat("Driver: {0} {1}\r\n", DriverFirstName, DriverLastName);
            sb.AppendFormat("DOB: {0}\r\n", DriverDateOfBirth.ToShortDateString());
            sb.AppendFormat("Address: {0}\r\n", DriverAddressOne);

            if (DriverAddressTwo != String.Empty)
            {
                sb.AppendLine(DriverAddressTwo + "\r\n");
            }

            sb.AppendFormat("City: {0}\tState: {1}\tZip: {2}\r\n", DriverCity, DriverState, DriverZip);
            sb.AppendLine("=============================================================================================");

            sb.AppendFormat("Violation Type: {0}\r\n", Enum.GetName(typeof(CitationType), CurrentCitationType));
            sb.AppendFormat("Reason For Stop: {0}\r\n", Enum.GetName(typeof(ViolationReason), CurrentViolationReason));
            sb.AppendFormat("Disposition: {0}\r\n", Enum.GetName(typeof(CitationType), CurrentCitationType));
            sb.AppendFormat("Notes: {0}\r\n", OfficerComments);

            return(sb.ToString());
        }
Пример #5
0
            public override long NextInt64()
            {
                long result = LocalRandom.NextInt64();

                AssertInRange(result, 0, long.MaxValue);
                return(result);
            }
Пример #6
0
            public override double NextDouble()
            {
                double result = LocalRandom.NextDouble();

                AssertInRange(result);
                return(result);
            }
Пример #7
0
 public Unit(string name, string description, int price, Grade mgrade) : base(name, description, price)
 {
     gender   = LocalRandom.RandomNumber(0, 100) < 70 ? Gender.Male : Gender.Female;
     race     = LocalRandom.RandomNumber(0, 100) < 95 ? Race.Human : Race.Elf;
     grade    = mgrade;
     unitName = GenerateName();
     weapon   = EquipementList.handgun;
 }
Пример #8
0
            public override int Next(int minValue, int maxValue)
            {
                if (minValue > maxValue)
                {
                    ThrowMinMaxValueSwapped();
                }

                return(LocalRandom.Next(minValue, maxValue));
            }
Пример #9
0
            public override int Next(int maxValue)
            {
                if (maxValue < 0)
                {
                    ThrowMaxValueMustBeNonNegative();
                }

                return(LocalRandom.Next(maxValue));
            }
Пример #10
0
 public void Init(LocalRandom random, int startYear, int numYears)
 {
     this.startYear = startYear;
     values         = new double[numYears + 1];
     for (var i = 0; i < values.Length; ++i)
     {
         values[i] = Sample(random);
     }
 }
Пример #11
0
            public override long NextInt64(long maxValue)
            {
                if (maxValue < 0)
                {
                    ThrowMaxValueMustBeNonNegative();
                }

                return(LocalRandom.NextInt64(maxValue));
            }
Пример #12
0
            public override long NextInt64(long minValue, long maxValue)
            {
                if (minValue > maxValue)
                {
                    ThrowMinMaxValueSwapped();
                }

                return(LocalRandom.NextInt64(minValue, maxValue));
            }
Пример #13
0
            public override void NextBytes(byte[] buffer)
            {
                if (buffer is null)
                {
                    ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer);
                }

                LocalRandom.NextBytes(buffer);
            }
Пример #14
0
    private string GenerateName()
    {
        StringBuilder str = new StringBuilder();

        for (int i = LocalRandom.RandomNumber(2, 4); i >= 0; i--)
        {
            str.Append(syllabes[LocalRandom.RandomNumber(0, syllabes.Length)]);
        }
        return(str.ToString());
    }
        public static double SampleSeries(int startYear, int endYear, LocalRandom random, double[] series)
        {
            if (startYear < 1928 || 2016 < startYear || endYear < 1928 || 2016 < endYear || endYear < startYear)
            {
                throw new ArgumentException("Start year and end year must be in 1928-2016");
            }
            var len   = endYear - startYear + 1;
            var index = random.Next(len) + (startYear - 1928);

            return(series[index] / 100.0);
        }
Пример #16
0
            public override long NextInt64(long minValue, long maxValue)
            {
                if (minValue > maxValue)
                {
                    ThrowMinMaxValueSwapped();
                }

                long result = LocalRandom.NextInt64(minValue, maxValue);

                AssertInRange(result, minValue, maxValue);
                return(result);
            }
Пример #17
0
            public override long NextInt64(long maxValue)
            {
                if (maxValue < 0)
                {
                    ThrowMaxValueMustBeNonNegative();
                }

                long result = LocalRandom.NextInt64(maxValue);

                AssertInRange(result, 0, maxValue);
                return(result);
            }
Пример #18
0
            public override int Next(int minValue, int maxValue)
            {
                if (minValue > maxValue)
                {
                    ThrowMinMaxValueSwapped();
                }

                int result = LocalRandom.Next(minValue, maxValue);

                AssertInRange(result, minValue, maxValue);
                return(result);
            }
Пример #19
0
            public override int Next(int maxValue)
            {
                if (maxValue < 0)
                {
                    ThrowMaxValueMustBeNonNegative();
                }

                int result = LocalRandom.Next(maxValue);

                AssertInRange(result, 0, maxValue);
                return(result);
            }
Пример #20
0
    private void Awake()
    {
        if (Instance != null)
        {
            Debug.LogError("Error: More than one localRandom in scene!");
            return;
        }
        Instance = this;

        UnityEngine.Random.InitState(DateTime.Now.Millisecond);
        randomValues = new float[randomLength];
    }
Пример #21
0
        double Sample(LocalRandom random)
        {
            // NOTE: don't use an interface and OO to select, makes JSON serialization a big mess
            switch (RateDistribution)
            {
            case RateDistribution.NormalDistribution:
                return(NormalDistribution.Sample(random, Parameters[0], Parameters[1]));

            case RateDistribution.LaplaceDistribution:
                return(LaplaceDistribution.Sample(random, Parameters[0], Parameters[1]));

            case RateDistribution.InflationModel:
                return(InflationModel.Sample(random));

            case RateDistribution.StockModel:
                return(StockModel.Sample(random));

            default:
                throw new NotImplementedException("Unknown RateType in Rate.Sample");
            }
        }
        /// <summary>
        /// Logic used for determining the ticket a driver will recieve.
        /// </summary>
        /// <param name="driver">Driver the officer has just pulled over.</param>
        /// <returns>The citation the driver recieved.</returns>
        public Citation PullOver(string officerRank, string officerFirstName, string officerLastName, int officerBadgeId, string officerNegativeComment, string officerPositiveComment, string driverFirstName, string driverLastName, string driverAddressOne, string driverAddressTwo, string driverCity, string driverState, string driverZipCode, DateTime driverDateOfBirth, bool driverIsImpaired)
        {
            var driversSpeed      = LocalRandom.GetRandomNumber(25, 95);
            var currentSpeedLimit = LocalRandom.GetRandomNumber(25, 75);
            var officersMood      = LocalRandom.GetRandomNumber(1, 10);
            var reasonNumber      = LocalRandom.GetRandomNumber(1, 4);
            var reason            = (ViolationReason)reasonNumber;


            Citation newCitation = new Citation()
            {
                OfficerRank            = officerRank,
                OfficerFirstName       = officerFirstName,
                OfficerLastName        = officerLastName,
                OfficerBadgeId         = officerBadgeId,
                OfficerComments        = string.Empty,
                DriverFirstName        = driverFirstName,
                DriverLastName         = driverLastName,
                DriverAddressOne       = driverAddressOne,
                DriverAddressTwo       = driverAddressTwo,
                DriverCity             = driverCity,
                DriverDateOfBirth      = driverDateOfBirth,
                DriverState            = driverState,
                DriverZip              = driverZipCode,
                CurrentViolationReason = reason,
            };

            CitationType  currentCitationType  = CitationType.Warning;
            ViolationType currentViolationType = ViolationType.Moving;
            var           speeding             = ViolationReason.Speeding; // Habit since linq does not like using Violation.foo in queries.
            var           impariment           = ViolationReason.SuspicionOfImpairment;

            // Handle speeding.
            if (newCitation.CurrentViolationReason == speeding)
            {
                var speedDifference = driversSpeed - currentSpeedLimit;

                newCitation.OfficerComments += string.Format("\r\n SpeedLimit: {0} Driver Speed: {1}  Speed: {2}\r\n"
                                                             , currentSpeedLimit, driversSpeed, speedDifference < 0 ? Math.Abs(speedDifference) + " under" : speedDifference + " over");


                // Cut a break if needed.
                string comment = string.Empty;
                speedDifference              = speedDifference = CheckBirthdaySpeed.GetSpeed(currentSpeedLimit, driversSpeed, driverDateOfBirth, out comment);
                newCitation.OfficerComments += comment;


                if (speedDifference > 0)
                {
                    if (speedDifference >= 5 && speedDifference <= 10)
                    {
                        currentCitationType = CitationType.SmallTicket;
                    }
                    else if (speedDifference >= 11 && speedDifference <= 15)
                    {
                        currentCitationType = CitationType.MediumTicket;
                    }
                    else if (speedDifference >= 16)
                    {
                        currentCitationType = CitationType.BigTicket;
                    }
                }
                else
                {
                    currentCitationType  = CitationType.Warning;
                    currentViolationType = ViolationType.Moving;
                }
            }
            else if (newCitation.CurrentViolationReason == impariment)
            {
                if (driverIsImpaired)
                {
                    currentCitationType          = CitationType.Ticket;
                    currentViolationType         = ViolationType.Moving;
                    newCitation.OfficerComments += "Driver was visibly impaired. \r\n";
                }
                else
                {
                    currentCitationType          = CitationType.Warning;
                    currentViolationType         = ViolationType.Moving;
                    newCitation.OfficerComments += "Driver was not visibly impaired. \r\n";
                }
            }
            else
            {
                // Other infractions are random chance.
                if (officersMood >= 5)
                {
                    currentCitationType = CitationType.Ticket;
                }
                else
                {
                    currentCitationType = CitationType.Warning;
                }
                if (reasonNumber <= 2)
                {
                    currentViolationType = ViolationType.Moving;
                }
                else
                {
                    currentViolationType = ViolationType.NonMoving;
                }
            }

            newCitation.CurrentCitationType  = currentCitationType;
            newCitation.CurrentViolationType = currentViolationType;

            if (currentCitationType == CitationType.Warning)
            {
                newCitation.OfficerComments += officerPositiveComment;
            }
            else
            {
                newCitation.OfficerComments += officerNegativeComment;
            }

            return(newCitation);
        }
Пример #23
0
        public static double Sample(LocalRandom random)
        {
            var len = annualInflation1957To2016.Length;

            return(annualInflation1957To2016[random.Next(len)] / 100.0);
        }
Пример #24
0
 public override int Next() => LocalRandom.Next();
Пример #25
0
 public override long NextInt64() => LocalRandom.NextInt64();
Пример #26
0
 public override float NextSingle() => LocalRandom.NextSingle();
Пример #27
0
 public override double NextDouble() => LocalRandom.NextDouble();
Пример #28
0
 public override void NextBytes(Span <byte> buffer) => LocalRandom.NextBytes(buffer);
Пример #29
0
 public static double Sample(LocalRandom random)
 {
     return(InvestmentTables.SampleSeries(1928, 2016, random, InvestmentTables.sp500Returns1928To2016));
 }