heres so far my code on my form1.cs
:
Quote
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace System7_12
{
public partial class Form1 : Form
{
public static ArrayList randomNums = new ArrayList();
public static int sysNum = 7;
public static Random rNum = new Random();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Clear();
randomNums.Clear();
CheckDuplication(randomNums);
//display random numbers...
foreach (int x in randomNums)
{
textBox1.Text += x + " ";
}
//permutation...
int combi = 0;
combi = (int)((permutation(sysNum)) / (permutation(6) * (permutation(sysNum - 6))));
MessageBox.Show(combi.ToString());
//display possible combinations...
for (int count = 1; count <= combi; count++)
{
//ArrayList sixNum =
// int count = 1;
// string combination = null;
// ArrayList display = new ArrayList();
// display = randomNums;
// display.RemoveAt(display.Count - count);
// foreach (int dsply in display)
// {
// combination += dsply.ToString() + " ";
// }
// listView1.Items.Add(count.ToString()).SubItems.Add(combination);
}
}
public int permutation(int x)
{
int num = 1;
for (int i = 1; i <= x; i++)
{
num *= i;
}
return num;
}
public void CheckDuplication(ArrayList randomNums)
{
bool change = true;
if (randomNums.Count < sysNum)
{
while (randomNums.Count < sysNum)
{
randomNums.Add(rNum.Next(1,43));
}
randomNums.Sort();
CheckDuplication(randomNums);
}
else if(randomNums.Count == sysNum)
{
for (int i = 0; i < randomNums.Count - 1; i++)
{
int plus = i + 1;
if ((int)randomNums[i] == (int)randomNums[plus]) randomNums.RemoveAt(i);
}
if (randomNums.Count == sysNum) change = false;
if(change == true) CheckDuplication(randomNums);
}
}
#region System Number radioButtons...
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true) sysNum = 7;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true) sysNum = 8;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked == true) sysNum = 9;
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
if (radioButton4.Checked == true) sysNum = 10;
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
if (radioButton5.Checked == true) sysNum = 11;
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
if (radioButton6.Checked == true) sysNum = 12;
}
#endregion
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace System7_12
{
public partial class Form1 : Form
{
public static ArrayList randomNums = new ArrayList();
public static int sysNum = 7;
public static Random rNum = new Random();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Clear();
randomNums.Clear();
CheckDuplication(randomNums);
//display random numbers...
foreach (int x in randomNums)
{
textBox1.Text += x + " ";
}
//permutation...
int combi = 0;
combi = (int)((permutation(sysNum)) / (permutation(6) * (permutation(sysNum - 6))));
MessageBox.Show(combi.ToString());
//display possible combinations...
for (int count = 1; count <= combi; count++)
{
//ArrayList sixNum =
// int count = 1;
// string combination = null;
// ArrayList display = new ArrayList();
// display = randomNums;
// display.RemoveAt(display.Count - count);
// foreach (int dsply in display)
// {
// combination += dsply.ToString() + " ";
// }
// listView1.Items.Add(count.ToString()).SubItems.Add(combination);
}
}
public int permutation(int x)
{
int num = 1;
for (int i = 1; i <= x; i++)
{
num *= i;
}
return num;
}
public void CheckDuplication(ArrayList randomNums)
{
bool change = true;
if (randomNums.Count < sysNum)
{
while (randomNums.Count < sysNum)
{
randomNums.Add(rNum.Next(1,43));
}
randomNums.Sort();
CheckDuplication(randomNums);
}
else if(randomNums.Count == sysNum)
{
for (int i = 0; i < randomNums.Count - 1; i++)
{
int plus = i + 1;
if ((int)randomNums[i] == (int)randomNums[plus]) randomNums.RemoveAt(i);
}
if (randomNums.Count == sysNum) change = false;
if(change == true) CheckDuplication(randomNums);
}
}
#region System Number radioButtons...
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true) sysNum = 7;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true) sysNum = 8;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked == true) sysNum = 9;
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
if (radioButton4.Checked == true) sysNum = 10;
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
if (radioButton5.Checked == true) sysNum = 11;
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
if (radioButton6.Checked == true) sysNum = 12;
}
#endregion
}
}


Sign In
Create Account


Back to top









