Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

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 273 views
1 answer 55 views
1 answer 151 views
1 answer 218 views
1 answer 63 views
...