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.Text;
- using System.Windows.Forms;
- namespace testRandomString
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string GenRandomString(string Alphabet, int Length)
- {
- //string Ret = "";
- Random rnd = new Random();
- StringBuilder sb = new StringBuilder(Length-1);
- int Position = 0;
- for (int i = 0; i < Length; i++)
- {
- Position = rnd.Next(0, Alphabet.Length-1);
- sb.Append(Alphabet[Position]);
- //Ret = Ret + Alphabet[Position]; //- так делать не стоит, в данном случае StringBuilder дает явный выигрыш в скорости
- }
- //return Ret;
- return sb.ToString();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- DateTime start = DateTime.Now;
- txtReturn.Text = GenRandomString("QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm.", 500000);
- DateTime end = DateTime.Now;
- MessageBox.Show((end - start).ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement