コード例 #1
0
        /// <summary>
        /// Helper method: generates a random index for refering to
        /// nurons or axons, garenteed to be unique. It returns negative
        /// if no sutch index can be found in a timely fassion.
        /// </summary>
        /// <returns>A random unique index</returns>
        private int RandIndex()
        {
            int index = -1;
            int count = 0;

            while (index < 0 && count < MAX_TRY)
            {
                //chooses a ranom positive interger
                index = rng.NextInt() & Int32.MaxValue;

                //invalidates the index if we have a collision
                if (nurons.HasKey(index))
                {
                    index = -1;
                }

                count++;
            }

            return(index);
        }