How to fill byte array with random byte values using NextBytes() in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] arr = new byte[13];

            Random random = new Random();

            random.NextBytes(arr);
            Print(arr);

            random.NextBytes(arr);
            Print(arr);
        }

        static void Print(byte[] array)
        {
            foreach (byte n in array)
                Console.Write(n + " ");

            Console.WriteLine();
        }
    }
}


/*
run:
    
24 182 178 225 98 190 230 195 100 27 95 115 74
194 53 155 134 82 240 197 23 26 35 231 33 169

*/

 



answered Feb 13, 2017 by avibootz

Related questions

2 answers 299 views
1 answer 63 views
1 answer 160 views
1 answer 225 views
1 answer 73 views
...