ASDV-C-Sharp/MP3/RandomNumberFileWriterOne_C.../Form1.cs

50 lines
1.5 KiB
C#

using System.Security.Cryptography;
namespace RandonNumberFileWriterOne_CalebFontenot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void executeButton_Click(object sender, EventArgs e)
{
//Get contents of textbox.
int timesToIterate, random;
if(!int.TryParse(iterateTextBox.Text, out timesToIterate))
{
MessageBox.Show("Invalid input");
}
// Create a StreamWriter object.
StreamWriter sw = null;
// Create rng object.
Random rng = new Random();
// Summon the Save As Dialog.
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
// Save target as a string for later usage.
string target = saveFileDialog1.FileName;
// Open a text file at our target.
sw = File.CreateText(target);
// Write a specified number of random integers
for (int i = 0; i < timesToIterate; i++)
{
random = rng.Next(1, 101);
sw.WriteLine(random);
}
sw.Close();
}
}
}
}