Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace NumerosAleatorias
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- lista.Items.Clear();
- for(int m= 0; m<10; m++){
- lista.Items.Add(CriarCodigo(m));
- }
- //criar numeros aleatorios de 0 a 99
- //Random gerador = new Random();
- //for (int m = 0; m < 20; m++)
- //{
- // int valor = gerador.Next(0,100);
- // lista.Items.Add(valor.ToString());
- //}
- }
- private string CriarCodigo(int seed, int numeroCarateres = 30)
- {
- //gerar string com carateres aleatorios
- StringBuilder str = new StringBuilder();
- string carateres = "ABCDEFGHIJKLMNOPKRSTUVWXYZabcdefghijklmnopkrstuvwxy";
- Random r = new Random(seed);
- int n = r.Next();
- for (int vezes = 0; vezes < numeroCarateres; vezes++)
- {
- Random rnd = new Random(DateTime.Now.Millisecond + seed + n);
- int x = rnd.Next(carateres.Length);
- str.Append(carateres[x]);
- n += 33;
- }
- //Devolve str
- return str.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement