Programas en C#

Friday, October 27, 2006

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i;

Random r = new Random(); // Creamos el objeto random, simplemente


//Y una vez tenemos el objeto, utilizaremos uno de esos tres métodos.

//1.- El método Next Tiene tres sobrecargas:
int aleat1 = r.Next();

// Le imponemos un máximo
int aleat2 = r.Next(10);

// Le imponemos un rango, por ejemplo queremos un número de 3 cifras
int aleat3 = r.Next(100, 999);

//2.- El método NextDouble
// Devuelve un double entre 0 y 1
double aleat4 = r.NextDouble();

//3.- El método NextBytes
byte[] buffer = new byte[100];
r.NextBytes(buffer);

Console.WriteLine("{0} - {1}- {2} -{3}",aleat1, aleat2, aleat3, aleat4);
i = 0;
while (i<100){
Console.Write("{0},", buffer[i]);
i++;
}
}
}
}

0 Comments:

Post a Comment

<< Home