0

Necesito especificarle un valor minimo y maximo a un arreglo usando el metodo .NextBytes().

        Random aleatorio = new Random();
        byte[] arreglo = new byte[4];
        aleatorio.NextBytes(arreglo);

        for (int i = 0; i < arreglo.Length; i++) {
            Console.WriteLine(arreglo[i]);
        }

1 respuesta 1

1

¡Buenas tardes! ¿Por qué necesitas hacerlo únicamente con el método .NextBytes?

Existe también Next (int minValue, int maxValue); en la clase Random que te permite introducir un intervalo. Aquí te dejo tu ejemplo modificado:

using System;

public class Program
{
    public static void Main()
    {
         Random aleatorio = new Random();       
         int minvalue = 0, maxvalue = 10;
         for (int i = 0; i < maxvalue ; i++) {
            Console.WriteLine(aleatorio.Next(minvalue , maxvalue));
         }
    }
}

Espero que te sirva de ayuda, ¡un saludo!

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.