Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with generating random fixtures
#1
I have 2 ListBoxes and a TextBox.
Each ListBox contains usernames which are manually added by the user.
I'd like random fixtures to be generated into the TextBox.

For example:

ListBox1:
Tom
Fred
Harry

ListBox2:
John
Dave
Bill

When the user hits generate, I'd like the fixtures to be randomly generated in the TextBox like so:

Tom vs Dave
Fred vs Bill
Harry vs John


Anybody help me out with this? I haven't coded in ages and I'm very rusty.

Reply
#2
I supose you're going to use an array for the inputted strings?
I'm not 100% sure, haven't coded in vb.net for ages. It's all java now.
I would know how to do it with the strings already there but not if you don't know what they are.

You could ask them to input the amount of strings they are going to insert and hold it in a variable such as ins then do
Dim num As Integer = random.Next(ins)

In java if I used an array I would just do array.length to find how many elements are in the array instead of asking them to input how many they are going to insert.
Not sure how to do that in vb.net though think you need to use upperbounds method.
[Image: burninglove4.png]
Reply
#3
Here is the code for the generate button:
Code:
Dim r As New Random
TextBox1.Text = String.Format("{0} vs {1}", ListBox1.Items(r.Next(0, ListBox1.Items.Count)), ListBox2.Items(r.Next(0, ListBox2.Items.Count)))
My software company: Porosis Software
Games: Terrantula
Apps: Mathanasis, ColorGrabber
Reply
#4
(03-14-2011, 10:28 AM)thanasis2028 Wrote: Here is the code for the generate button:
Code:
Dim r As New Random
TextBox1.Text = String.Format("{0} vs {1}", ListBox1.Items(r.Next(0, ListBox1.Items.Count)), ListBox2.Items(r.Next(0, ListBox2.Items.Count)))

Thank you that works, but it only generates 1 fixture. I need each player to have a random fixture.

Thanks.

Reply
#5
You need to create a dynamic array.
Get the length of the array then generate the random number as I showed.
Then tell it to put the element of the array into the textbox.

The only problem would be it may put the same username more than once. I'm not sure if it does though.
[Image: burninglove4.png]
Reply
#6
You will have to use the code i gave you many times but changing the line:
Code:
TextBox1.Text = String.Format("{0} vs {1}", ListBox1.Items(r.Next(0, ListBox1.Items.Count)), ListBox2.Items(r.Next(0, ListBox2.Items.Count)))
with
Code:
TextBox1.AppendText(String.Format("{0} vs {1}", ListBox1.Items(r.Next(0, ListBox1.Items.Count)), ListBox2.Items(r.Next(0, ListBox2.Items.Count))))
You have to find a way to prevent the same name from appearing in the list again. This might be a little hard...
My software company: Porosis Software
Games: Terrantula
Apps: Mathanasis, ColorGrabber
Reply
#7
(03-15-2011, 12:17 PM)thanasis2028 Wrote: You will have to use the code i gave you many times but changing the line:
Code:
TextBox1.Text = String.Format("{0} vs {1}", ListBox1.Items(r.Next(0, ListBox1.Items.Count)), ListBox2.Items(r.Next(0, ListBox2.Items.Count)))
with
Code:
TextBox1.AppendText(String.Format("{0} vs {1}", ListBox1.Items(r.Next(0, ListBox1.Items.Count)), ListBox2.Items(r.Next(0, ListBox2.Items.Count))))
You have to find a way to prevent the same name from appearing in the list again. This might be a little hard...

Thanks but I think what Untouch suggested is a much more reliable solution.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [How to] Create random strings(upper,lower and integers)[Src] Modestep 11 2,948 05-14-2011, 02:17 AM
Last Post: モrainee
  [Snippet] Random pick from list (Range) euverve 0 693 05-12-2011, 08:22 AM
Last Post: euverve
  [Tut] Generating Random Strings (200 Random Results = LIMIT) [Tut] Resistance 7 1,859 04-12-2011, 03:18 PM
Last Post: Resistance
  Generate Random Numbers & Letters [ Small Function ] MYPE 22 4,162 04-02-2011, 05:25 PM
Last Post: Pyratepig
  Random selection from list? pers2981 1 734 11-14-2010, 01:46 PM
Last Post: KoBE

Forum Jump:


Users browsing this thread: 3 Guest(s)