NextBytes() 공개 정적인 메소드

public static NextBytes ( byte buffer ) : void
buffer byte
리턴 void
예제 #1
0
        /// <summary>
        ///     Gets a random mac address.
        /// </summary>
        /// <param name="prefix">The prefix.</param>
        /// <param name="groupSplit">The group split.</param>
        /// <returns>The random mac address.</returns>
        public static string MacAddress(string prefix = null, char groupSplit = ':')
        {
            const int maxBufferLength = 6;

            int prefixesLength = prefix == null ? 0 : prefix.Split(groupSplit).Length;

            if (prefix != null && prefixesLength < maxBufferLength &&
                !prefix.EndsWith(groupSplit.ToString(), StringComparison.CurrentCulture))
            {
                prefix += groupSplit;
            }

            var buffer = new byte[maxBufferLength - prefixesLength];

            RandomNumber.NextBytes(buffer);
            string result = string.Concat(buffer.Select(x => x.ToString("X2", CultureInfo.CurrentCulture) + groupSplit));

            return(prefix + result.TrimEnd(groupSplit));
        }