Example #1
0
        public virtual void DictionaryOfClasses()
        {
            Dictionary <Helper1, Helper1> source = new Dictionary <Helper1, Helper1>();

            for (int i = 0; i < 1000; i++)
            {
                source.Add(new Helper1()
                {
                    PropOne = RandGen.GenerateInt()
                },
                           new Helper1()
                {
                    PropOne = RandGen.GenerateInt()
                });
            }

            var dest = GetClone(source, 2001);

            Assert.NotNull(dest);
            Assert.Equal(dest.Count, source.Count);

            var destKeys     = dest.Keys.ToList();
            var destValues   = dest.Values.ToList();
            var sourceKeys   = source.Keys.ToList();
            var sourceValues = source.Values.ToList();

            for (int i = 0; i < dest.Keys.Count; i++)
            {
                Assert.NotSame(destKeys[i], sourceKeys[i]);
                Assert.Equal(destKeys[i].PropOne, sourceKeys[i].PropOne);

                Assert.NotSame(destValues[i], sourceValues[i]);
                Assert.Equal(destValues[i].PropOne, sourceValues[i].PropOne);
            }
        }
Example #2
0
        public virtual void ListOfClasses()
        {
            List <Helper2> source = new List <Helper2>();

            for (int i = 0; i < 1000; i++)
            {
                source.Add(new Helper2()
                {
                    Helper = new Helper1()
                    {
                        PropOne = RandGen.GenerateInt()
                    }
                });
            }

            List <Helper2> dest = GetClone(source, 2001);

            Assert.NotNull(dest);
            Assert.Equal(dest.Count, source.Count);

            for (int i = 0; i < dest.Count; i++)
            {
                Assert.NotSame(dest[i], source[i]);
                Assert.NotSame(dest[i].Helper, source[i].Helper);
                Assert.Equal(dest[i].Helper.PropOne, source[i].Helper.PropOne);
            }
        }
Example #3
0
            public static Vector3 randomOnRoad(Vector3 me, float radius)
            {
                float   t;
                Vector3 o = new Vector3(me.X, me.Y, me.Z);

                o.X += 2 * radius * ((float)RandGen.NextDouble()) - radius;
                o.Y += 2 * radius * ((float)RandGen.NextDouble()) - radius;

                unsafe
                {
                    Function.Call(Hash.GET_GROUND_Z_FOR_3D_COORD, o.X, o.Y, 10000f, &t);
                    //Function.Call(Hash.GET_CLOSEST_ROAD, 1986.5509f, 3802.58447f, 32.2808743f, 1.0f /*default: 1f*/, 1 /*default: 1*/, &x1, &y1, &za, &x2, &y2, false /*default: False*/);
                    if (t == 0)
                    {
                        return(new Vector3(0, 0, 0));
                    }

                    bool onR = Function.Call <bool>(Hash.IS_POINT_ON_ROAD, o.X, o.Y, t, 0);

                    o.Z = t;

                    if (onR)
                    {
                        return(o);
                    }
                }
                return(new Vector3(0, 0, 0));
            }
Example #4
0
        public virtual void ListStringArrays_DuplicateReuse()
        {
            var helper = RandGen
                         .GenerateStringList(20, 5).
                         ToArray();

            List <string[]> source = new List <string[]>()
            {
                helper,
                helper,
                helper,
                helper
            };

            var dest = GetClone(source, 2);

            Assert.NotNull(dest);
            Assert.NotSame(dest, source);
            Assert.Equal(dest.Count, source.Count);

            var firstItem = dest[0];

            for (int i = 0; i < dest.Count; i++)
            {
                Assert.NotSame(source[i], dest[i]);
                Assert.Same(firstItem, dest[i]);
                Assert.Equal(source[i].Length, dest[i].Length);

                for (int j = 0; j < dest[i].Length; j++)
                {
                    Assert.Equal(source[i][j], dest[i][j]);
                }
            }
        }
Example #5
0
        public virtual void InheritList_Class()
        {
            var source = new Helper3 <Helper1>()
            {
                PropOne = RandGen.GenerateInt()
            };

            for (int i = 0; i < 1000; i++)
            {
                source.Add(new Helper1()
                {
                    PropOne = RandGen.GenerateInt()
                });
            }
            ;

            var target = GetClone(source, 1001);

            Assert.NotSame(source, target);
            Assert.Equal(target.Count, source.Count);
            Assert.Equal(target.PropOne, source.PropOne);

            for (int i = 0; i < target.Count; i++)
            {
                Assert.NotSame(target[i], source[i]);
                Assert.Equal(target[i].PropOne, source[i].PropOne);
            }
        }
Example #6
0
            public static long RandomLong()
            {
                var buffer = new byte[8];

                RandGen.NextBytes(buffer);
                return(BitConverter.ToInt64(buffer, 0));
            }
Example #7
0
        public void IRealOnlyList_Interface()
        {
            IReadOnlyList <MyTmpInterface> source = new List <MyTmpInterface>()
            {
                new Helper1()
                {
                    PropOne = RandGen.GenerateInt()
                },
                new Helper1_1()
                {
                    PropOne = RandGen.GenerateInt()
                },
                new HelperStruct3()
                {
                    PropOne = RandGen.GenerateInt()
                }
            };

            var dest = GetClone(source, 3);

            Assert.NotNull(dest);
            Assert.NotSame(dest, source);

            Assert.IsAssignableFrom <Helper1>(dest[0]);
            Assert.IsAssignableFrom <Helper1_1>(dest[1]);
            Assert.IsAssignableFrom <HelperStruct3>(dest[2]);

            Assert.Equal(source[0].PropOne, dest[0].PropOne);
            Assert.Equal(source[1].PropOne, dest[1].PropOne);
            Assert.Equal(source[2].PropOne, dest[2].PropOne);
        }
Example #8
0
        private static void AssertAccess <T>() where T : new()
        {
            var intersect = Intersect <T> .Create();

            T source = new T();
            T dest   = new T();

            // Make sure all public and private field/props
            // are initialized.
            foreach (var i in intersect)
            {
                var randValue = RandGen.GenerateString(10);
                var setter    = i.Setter.GetDelegate <object>();
                var getter    = i.Getter.GetDelegate <object>();
                setter(ref source, randValue);

                var actual = getter(ref source);
                Assert.Equal(randValue, actual);
            }

            foreach (var i in intersect)
            {
                var getter = i.Getter.GetDelegate <object>();
                var setter = i.Setter.GetDelegate <object>();
                setter(ref dest, getter(ref source));
            }

            foreach (var i in intersect)
            {
                var getter = i.Getter.GetDelegate <object>();
                Assert.Same(getter(ref source), getter(ref dest));
            }
        }
Example #9
0
        /// <summary>
        /// Construct a set of point. Note that maximal number of point if limited
        /// due to radius parameter in a finite rectangular shape (with, height).
        /// That is, a finite maximal number of sample exists and sample size will
        /// then eventually lower that the required sampleSize as a parameter.
        /// </summary>
        /// <param name="sampleSize">Maximal number of point to sample.</param>
        /// <param name="randInCircle">Used to compute random delta from a sample.
        /// Arguments are radius and radius x 2</param>
        public void BuildSample(int sampleSize, Func <double, double, Vec3> randInSphere)
        {
            // Register random function used
            randomFunc = randInSphere;

            // Cols represent the number of cell for the width (x coordinate)
            // Initialize will null by default
            _grid       = new Vec3[_rows, _cols, _depths];
            _activeList = new List <Vec3>();
            _count      = 0;

            // Add first point in the center
            Vec3 firstSample = new Vec3(_width / 2.0f, _height / 2.0f, _depth / 2.0f);

            _activeList.Add(firstSample);
            Store(firstSample);

            // Try adding sampleSize - 1 other samples
            while (_count < sampleSize && _activeList.Count > 0)
            {
                // Select a site from the list
                int  sampleIndex = RandGen.NextInt(0, _activeList.Count);
                Vec3 sample      = _activeList[sampleIndex];

                // Try adding a new sample
                if (!TryAddCandidate(sample))
                {
                    // If not possible remove sample from active list
                    _activeList.RemoveAt(sampleIndex);
                }
            }
        }
Example #10
0
 private void SetZoneSeeds()
 {
     foreach (Zone zone in zones)
     {
         zone.SetZoneSeed(RandGen.GenRandomSeed());
     }
 }
Example #11
0
        public void Primitives()
        {
            var source = new Tuple <int, string, int, int, int, int, int, Tuple <int> >(
                RandGen.GenerateInt(),
                RandGen.GenerateString(10),
                RandGen.GenerateInt(),
                RandGen.GenerateInt(),
                RandGen.GenerateInt(),
                RandGen.GenerateInt(),
                RandGen.GenerateInt(),
                new Tuple <int>(RandGen.GenerateInt()));

            var target = GetClone(source, 2);

            Assert.Equal(source, target);
            Assert.NotSame(source, target);
            Assert.Equal(source.Item1, target.Item1);
            Assert.Equal(source.Item2, target.Item2);
            Assert.Same(source.Item2, target.Item2);
            Assert.Equal(source.Item3, target.Item3);
            Assert.Equal(source.Item4, target.Item4);
            Assert.Equal(source.Item5, target.Item5);
            Assert.Equal(source.Item6, target.Item6);
            Assert.Equal(source.Item7, target.Item7);
            Assert.Equal(source.Rest, target.Rest);
            Assert.NotSame(source.Rest, target.Rest);
        }
Example #12
0
        private double UniformLuck()
        {
            double newLuckValue = RandGen.Next(-100, 101) / 1000.0;  // The range is [-100, 101) (inclusive left, exclusive right)

            Monitor.Log($"Uniform NewLuck: {newLuckValue}", LogLevel.Trace);
            return(newLuckValue);
        }
Example #13
0
        private string GenerateMaleFirstName()
        {
            var index = RandGen.Next(0, _maleFirstNames.Count);

            Sex = Gender.Male;

            return(_maleFirstNames.AsEnumerable().ElementAt(index));
        }
Example #14
0
 private void Start()
 {
     spawnRoom   = GameObject.Find("SpawnRoom");
     currentZone = zones[0];
     RandGen.SetSeed(newSeed);
     SetZoneSeeds();
     ui.UpdateZone(currentZone);
 }
Example #15
0
        /*public override void Mitosis(int n)
         * {
         *      // mitosis is the process of cell division resulting in two (here n)
         *      // daughter cells which are identical to the original nucleus
         *      for (int i = 0; i < n; i++)
         *      {
         *              // TODO: Hard coded line
         *              var mutatedPattern = GetMutatedPattern(50, true);
         *              var newCell = new HelperTCell(Parent, mutatedPattern);
         *              //Parent.AddCell(newCell);
         *      }
         *      Apoptosis();
         * }*/

        protected override void OnLifeEnd()
        {
            // TODO: MODIFICATION FOR HYPERMUTATION
            if (ExtraLifespan > 0 && RandGen.Next(0, 3) == 1)
            {
                Mitosis(1);
            }
            base.OnLifeEnd();
        }
Example #16
0
        /// <summary>
        /// Gets the random city, state, zip line from the resource file
        /// </summary>
        private void GetRandomCityStateZip()
        {
            if (_citystatezip == null)
            {
                _citystatezip = ReadResourceByLine(CityFile);
            }
            var index = RandGen.Next(0, _citystatezip.Count);

            cityStateZipLine = _citystatezip.AsEnumerable().ElementAt(index);
        }
Example #17
0
        public MainForm()
        {
            InitializeComponent();
            comboBox_target.SelectedIndex = 0;
            comboBox1.SelectedIndex       = 0;
            updateFormEnabling();
            ctrl = new Controller();
            Random randa = new Random();

            rand = new RandGen(randa.Next(4324324), randa.Next(434343));
        }
Example #18
0
 internal void SanityCheck()
 {
     sb.Clear()
     .Append("Sanity Test: Five random numbers: ");
     for (int i = 0; i < 5; i++)
     {
         sb.Append(RandGen.Next().ToString())
         .Append(" ");
     }
     this.Monitor.Log(sb.ToString(), LogLevel.Debug);
 }
Example #19
0
            public CNtruRandContext(RandGen rand_gen, IntPtr seed, ushort seed_len, IntPtr state)
            {
                IntPtr rand_gen_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(rand_gen));

                Marshal.StructureToPtr(rand_gen, rand_gen_ptr, false);
                this.rand_gen = rand_gen_ptr;
                this.seed     = seed;
                this.seed_len = seed_len;
                this.state    = state;
                ///Marshal.FreeHGlobal(rand_gen_ptr);  Does This break the struct? or does not doing this cause a memory leak
            }
Example #20
0
        public void Struct_AsInterface()
        {
            MyTmpInterface source = new HelperStruct3()
            {
                PropOne = RandGen.GenerateInt()
            };

            var dest = GetClone(source, 0);

            Assert.NotNull(dest);
            Assert.Equal(source.PropOne, dest.PropOne);
        }
Example #21
0
        public void Setup()
        {
            _intArray  = new[] { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            _byteArray = RandGen.GenerateByteArray(1000);

            _stringArray = Enumerable
                           .Range(0, 10)
                           .Select(x => RandGen.GenerateString(10))
                           .ToArray();

            _timeSpanArray = Enumerable
                             .Range(0, 10)
                             .Select(x => new TimeSpan(x))
                             .ToArray();

            _dateTimeArray = Enumerable
                             .Range(0, 10)
                             .Select(x => DateTime.Now)
                             .ToArray();

            Func <string> func = () =>
            {
                return(string.Empty);
            };

            _delegateArray = Enumerable
                             .Range(0, 10)
                             .Select(x => func)
                             .ToArray();

            _arrayOfStringArrays = new string[][]
            {
                new string [] { "one", "two" },
                new string [] { "three", "four" }
            };

            _arrayOfClasses = Enumerable
                              .Range(0, 100)
                              .Select(x => new Helper1()
            {
                PropOne = RandGen.GenerateInt()
            })
                              .ToArray();

            _arrayOfStructs = Enumerable
                              .Range(0, 100)
                              .Select(x => new HelperStruct1()
            {
                PropOne = RandGen.GenerateInt()
            })
                              .ToArray();
        }
Example #22
0
        /**************************************************
        * Mathemagic here
        **************************************************/

        private double GaussianLuck()
        {
            // Box-Muller transform
            // See: https://stackoverflow.com/a/218600/149900
            double u1            = 1.0 - RandGen.NextDouble();                          // uniform(0,1] random doubles. subtraction necessary to prevent getting u1=0.0, which will blow up Math.Log
            double u2            = RandGen.NextDouble();                                // no such problem for u2. [0,1) is perfectly okay for Math.Sin
            double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(TAU * u2); // gaussian distrib around 0
            double randNormal    = (double)Config.GaussianLuckStdDev * randStdNormal;   // stretch horizontally to get wanted curve
            double newLuckValue  = randNormal / 1000.0;

            Monitor.Log($"Gaussian NewLuck: {newLuckValue}", LogLevel.Trace);
            return(newLuckValue);
        }
Example #23
0
        /// <summary>
        /// Sends a cell to a randomly-selected type-specific tissue.
        /// </summary>
        /// <param name="cell">The cell to be sent to another tissue.</param>
        /// <param name="tissueType">The type of destination tissue.</param>
        protected void SendCellToRandomTissue(Cell cell, TissueType tissueType)
        {
            var typeAddresses =
                from address in addressList where (address.Value == tissueType) select address.Key;

            var typeCount = typeAddresses.Count();

            if (typeCount > 0)
            {
                int randIx = RandGen.Next(0, typeCount);
                SendCell(cell, typeAddresses.ElementAt(randIx));
            }
        }
Example #24
0
        private void getValidRandomFirstTile(GameBoard i_Board, out int o_Row, out int o_Col)
        {
            int randRow = RandGen.Next(k_MinValue, i_Board.r_Rows);
            int randCol = RandGen.Next(k_MinValue, i_Board.r_Cols);

            while (i_Board.m_State[randRow, randCol] == eCellState.Open)
            {
                randRow = RandGen.Next(k_MinValue, i_Board.r_Rows);
                randCol = RandGen.Next(k_MinValue, i_Board.r_Cols);
            }

            o_Row = randRow;
            o_Col = randCol;
        }
Example #25
0
        public void IRealOnlyList_String()
        {
            IReadOnlyList <string> source = new List <string>()
            {
                RandGen.GenerateString(10)
            };

            var dest = GetClone(source, 1);

            Assert.NotNull(dest);
            Assert.NotSame(dest, source);
            Assert.Equal(dest.Count, source.Count);
            Assert.Equal(dest[0], source[0]);
        }
Example #26
0
        public void SimpleStruct()
        {
            HelperStruct2 source = new HelperStruct2()
            {
                Helper = new HelperStruct1()
                {
                    PropOne = RandGen.GenerateInt()
                }
            };

            HelperStruct2 target = GetClone(source, 0);

            Assert.Equal(source, target);
            Assert.Equal(source.Helper.PropOne, target.Helper.PropOne);
        }
Example #27
0
        public HelperTCell(ITissue parent, int mpLen)
            : base(CellType.Helper, parent)
        {
            Activators = new List <Address>();

            // generate a random molecular pattern
            // NOTE: pattern vectors should be normalized
            var pat = new double[mpLen];

            for (int i = 0; i < mpLen; i++)
            {
                pat[i] = RandGen.NextDouble();
            }
            Pattern = new MolecularPattern(pat);
        }
Example #28
0
        public FibberConfiguration For <T>(RandGen randomGenerator)
        {
            if (TypeGenerators.ContainsKey(typeof(T)))
            {
                throw new ArgumentException(string.Format("There is already a generator registered for type: {0}.", typeof(T).ToString()));
            }

            dynamic expando = new ExpandoObject();

            expando.Generator = randomGenerator;

            TypeGenerators.Add(typeof(T), expando);

            return(this);
        }
Example #29
0
        /// <summary>
        /// Create service instances.
        /// </summary>
        /// <param name="instances">Create and initialize the service instances</param>
        /// <param name="isRandomNumberOfPartitions">True if random number of Partitions (less than or equal to max number of partitions) per instance, false initialize max number of partitions</param>
        /// <param name="numOfPartitionsPerInstance">Number of partitions per instance</param>
        static void InitializeInstances(InstanceRecord[] instances, bool isRandomNumberOfPartitions, int numOfPartitionsPerInstance)
        {
            for (int instanceIndex = 0; instanceIndex < instances.Count(); instanceIndex++)
            {
                Uri instanceName = new Uri("fabric:/test/svcInstance/" + instanceIndex);

                // Initialize partitions
                int partitionCount = numOfPartitionsPerInstance;
                if (isRandomNumberOfPartitions)
                {
                    partitionCount = RandGen.Next(1, numOfPartitionsPerInstance);
                }

                instances[instanceIndex] = new InstanceRecord(instanceName, partitionCount);
            }
        }
Example #30
0
 public static void CreateMaze(Zone loadZone, IntVector2 mapSize)
 {
     if (mazeInstance != null)
     {
         ResetGame();
     }
     currentMapSize = mapSize;
     RandGen.SetSeed(loadZone.GetZoneSeed());
     currentZone       = loadZone;
     mazePrefab        = loadZone.mazePrefab;
     mazeInstance      = Instantiate(mazePrefab) as Maze;
     mazeInstance.name = "Maze";
     maze = mazeInstance.Generate(mapSize);
     CreateSpawns();
     SetUpPlayer();
 }