Created
April 6, 2017 21:20
-
-
Save Reflej0/d8407103d1a4eba8c0be24f63df24f1a to your computer and use it in GitHub Desktop.
Algoritmo en C# para generar numeros aleatorios dentro de un rango definido.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Crack!
excelente me sirvió gracias!!
Gracias, explicaste mejor que los documentos de microsoft
Grande !!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!