Skip to content

Instantly share code, notes, and snippets.

@Reflej0
Created April 6, 2017 21:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Reflej0/d8407103d1a4eba8c0be24f63df24f1a to your computer and use it in GitHub Desktop.
Save Reflej0/d8407103d1a4eba8c0be24f63df24f1a to your computer and use it in GitHub Desktop.
Algoritmo en C# para generar numeros aleatorios dentro de un rango definido.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Aleatorio
{
class Program
{
static void Main(string[] args)
{
// Crear objeto. Utiliza el reloj del sistema para crear una semilla.
Random rnd = new Random();
// Obtiene un número natural (incluye el 0) aleatorio entre 0 e int.MaxValue
int numeroSinCotaArbitraria = rnd.Next();
Console.WriteLine("Número sin cotas: {0}", numeroSinCotaArbitraria);
// Obtiene, en este ejemplo, un número natural (incluye el 0)
// aleatorio entre 0 y 5.
int numeroConCotaSuperior = rnd.Next(5);
Console.WriteLine("Número entre 0 y 5: {0}", numeroConCotaSuperior);
// Obtiene, en este ejemplo, un número natural (incluye el 0)
// aleatorio entre 4 (inclusive ) y 10.
int numeroConDosCotas = rnd.Next(4, 10);
Console.WriteLine("Número entre 4 y 10: {0}", numeroConDosCotas);
}
}
}
@echavilla
Copy link

Thank you!

@rodrivega96
Copy link

Crack!

@sergioTorres15
Copy link

excelente me sirvió gracias!!

@raidenrere
Copy link

Gracias, explicaste mejor que los documentos de microsoft

@TorresMBA
Copy link

Grande !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment