예제 #1
0
        public static int GenerateNumber()
        {
            uint id = 0;

            do
            {
                if (ServerContext.Config?.UseIncrementalSerials ?? false)
                {
                    Interlocked.Increment(ref SERIAL);
                }
                else
                {
                    id = (uint)Random.Next();
                }
            } while (GeneratedNumbers
                     .Contains(ServerContext.Config?.UseIncrementalSerials ?? false ? SERIAL : (int)id));

            if (ServerContext.Config?.UseIncrementalSerials ?? false)
            {
                return(SERIAL);
            }

            lock (Random)
            {
                GeneratedNumbers.Add(SERIAL);
            }

            return((int)id);
        }
예제 #2
0
        public static int GenerateNumber()
        {
            var id = 0;

            do
            {
                lock (Random)
                {
                    id = Random.Next();
                }
            } while (GeneratedNumbers.Contains(id));

            return(id);
        }