# some advice on grouping numbers

• (2 Pages)
• 1
• 2

## 28 Replies - 1144 Views - Last Post: 21 October 2010 - 03:45 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=195287&amp;s=6b2f389cd295ac5969e4235d7b872a4e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 8
• Posts: 160
• Joined: 09-August 08

# some advice on grouping numbers

Posted 16 October 2010 - 06:28 AM

hi all... i have a richtextbox that has around 30 numbers in...

348,325,734,12,97,457,264,390,909

and so on... now im looking for some way to make random gruops with this numbers in....

this is for a racing game... it is to make random races with differnt racers in.. so it makes a set of "heats" and then winners go into a final....

how could i do this in vb.net?

Kev
Is This A Good Question/Topic? 0

## Replies To: some advice on grouping numbers

### #2 Amrykid

• 4+1=Moo

Reputation: 146
• Posts: 1,571
• Joined: 16-December 08

## Re: some advice on grouping numbers

Posted 16 October 2010 - 06:50 AM

What kind of groups? Could you be more specific?

Reputation: 8
• Posts: 160
• Joined: 09-August 08

## Re: some advice on grouping numbers

Posted 16 October 2010 - 06:58 AM

well im looking to put these numbers in random groups of say 15 (IE: 15 of the numbers listed in each gruop)

now there could be from 30 to 130 numbers

at the mo we have to make the groups ourselves... IE: take each number and just putit in a goup... but some racers see it as we make the groups unfair... so i would like to make a application that makes the gruops for me that way i have no control on what racer is in what group with other racers

hops this helps abit

Kev

### #4 fixo

• D.I.C Regular

Reputation: 83
• Posts: 335
• Joined: 10-May 09

## Re: some advice on grouping numbers

Posted 17 October 2010 - 01:37 AM

TADS, on 16 October 2010 - 05:58 AM, said:

well im looking to put these numbers in random groups of say 15 (IE: 15 of the numbers listed in each gruop)

now there could be from 30 to 130 numbers

at the mo we have to make the groups ourselves... IE: take each number and just putit in a goup... but some racers see it as we make the groups unfair... so i would like to make a application that makes the gruops for me that way i have no control on what racer is in what group with other racers

hops this helps abit

Kev

Not sure about if this will create randoms correct
Anyway you can try it
(not tested extensively)
```    Public Sub CreateRandomGrous()

Using sw As StreamWriter = New StreamWriter("C:\Test\groups.txt") '<-- change the full path here
Dim rnd = New Random()

Dim c As Integer = 0
Dim arr = Array.CreateInstance(GetType(Int32), 100)
For i As Integer = 30 To 129
arr(i - 30) = i
Next

Dim numbers = From n In arr
Let i = n
Where (n >= 30 And n <= 130)
Let Racer = rnd.Next(30, 130)
Select New With {Racer}

Dim groups As New List(Of ArrayList)()
For i As Integer = 0 To numbers.Count() - 1 Step 15
Dim group As New ArrayList()
For j As Integer = 0 To 14
Next
Next
Dim cnt As Integer = 1
For i As Integer = 0 To groups.Count - 1
sw.WriteLine("=== Group {0} ===", cnt)
For j As Integer = 0 To groups.Item(0).Count - 1

sw.WriteLine(vbTab & groups.Item(i)(j).Racer)

Next

cnt = cnt + 1
Next
sw.Close()
End Using
End Sub
```

~'J'~

Reputation: 8
• Posts: 160
• Joined: 09-August 08

## Re: some advice on grouping numbers

Posted 17 October 2010 - 12:13 PM

Thanks just going to give it ago now

Reputation: 8
• Posts: 160
• Joined: 09-August 08

## Re: some advice on grouping numbers

Posted 18 October 2010 - 09:37 AM

i have just tryed this.... and works ok.... but im unsure on how i can use it in what im trying to do.... i have a richtextbox with he numbers that i need in it... its the peoples race numbers.... IE: 348,325,734,12,97,457,264,390,909 an so on... i could save that to a txt file and then read it in again and add the numbers to a arraylist but then how do i then make them go into the groups at random?

sorry if his seams a silly question but i have been looking at this and cant work it out

thanks

Kev

### #7 fixo

• D.I.C Regular

Reputation: 83
• Posts: 335
• Joined: 10-May 09

## Re: some advice on grouping numbers

Posted 18 October 2010 - 01:51 PM

TADS, on 18 October 2010 - 08:37 AM, said:

i have just tryed this.... and works ok.... but im unsure on how i can use it in what im trying to do.... i have a richtextbox with he numbers that i need in it... its the peoples race numbers.... IE: 348,325,734,12,97,457,264,390,909 an so on... i could save that to a txt file and then read it in again and add the numbers to a arraylist but then how do i then make them go into the groups at random?

sorry if his seams a silly question but i have been looking at this and cant work it out

thanks

Kev

Sorry, Kev
Now is too late here
I'll post my response tomorrow
CU

~'J'~

Reputation: 8
• Posts: 160
• Joined: 09-August 08

## Re: some advice on grouping numbers

Posted 18 October 2010 - 02:00 PM

ok thanks for the help

### #9 fixo

• D.I.C Regular

Reputation: 83
• Posts: 335
• Joined: 10-May 09

## Re: some advice on grouping numbers

Posted 18 October 2010 - 02:41 PM

TADS, on 18 October 2010 - 01:00 PM, said:

ok thanks for the help

Ah, can't sleep without solution
Here you go
Add 2 richtexboxes and drop button on form
Here is event on click (your first richtextbox
must be filled with racers before)

```    Private Sub btnGrouping_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrouping.Click
Dim rnd = New Random()
Dim RacerIds As ArrayList = New ArrayList(Me.RichTextBox1.Lines)

Dim Racers = From n In RacerIds
Let i = RacerIds.IndexOf(n)
Where (i >= 0 And i <= 99)
Let Position = rnd.Next(0, 99)
Let Racer = RacerIds.Item(Position)
Select New With {Position, Racer}

Dim dispGrous As ArrayList = New ArrayList
Dim groups As New List(Of ArrayList)()
For i As Integer = 0 To Racers.Count() - 1 Step 15
Dim group As New ArrayList()
Dim line = ""
For j As Integer = 0 To 14
line = line & vbTab & Racers(i).Racer
Next
Next
Me.RichTextBox2.Lines = dispGrous.ToArray(GetType(String))
'' you can write 'groups' in text box with code from my post above here
End Sub
```

~'J'~

Reputation: 8
• Posts: 160
• Joined: 09-August 08

## Re: some advice on grouping numbers

Posted 19 October 2010 - 05:14 AM

WOW thanks i will test this later when all jobs are done... thanks again

### #11 fixo

• D.I.C Regular

Reputation: 83
• Posts: 335
• Joined: 10-May 09

## Re: some advice on grouping numbers

Posted 19 October 2010 - 05:17 AM

TADS, on 19 October 2010 - 04:14 AM, said:

WOW thanks i will test this later when all jobs are done... thanks again

Let me know how it will work on your end
Regards,

~'J'~

Reputation: 8
• Posts: 160
• Joined: 09-August 08

## Re: some advice on grouping numbers

Posted 19 October 2010 - 09:41 AM

ok this is what i have found....

change richtextbox1 to carlist and richtexbox2 to heats...

``` Public Sub makegroups()
Dim rnd = New Random()
Dim RacerIds As ArrayList = New ArrayList(Me.carlist.Lines)

Dim Racers = From n In RacerIds Let i = RacerIds.IndexOf(n) Where (i >= 0 And i <= 99) Let Position = rnd.Next(0, 99) Let Racer = RacerIds.Item(Position) Select New With {Position, Racer}

Dim dispGrous As ArrayList = New ArrayList
Dim groups As New List(Of ArrayList)()
For i As Integer = 0 To Racers.Count() - 1 Step 15
Dim group As New ArrayList()
Dim line = ""
For j As Integer = 0 To 14
line = line & vbTab & Racers(i).Racer
Next
Next
Me.heats.Lines = dispGrous.ToArray(GetType(String))
End Sub

```

i get error on...

```For i As Integer = 0 To Racers.Count() - 1 Step 15
```

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

if you could help on this that would be brill

Kev

### #13 fixo

• D.I.C Regular

Reputation: 83
• Posts: 335
• Joined: 10-May 09

## Re: some advice on grouping numbers

Posted 19 October 2010 - 09:57 AM

TADS, on 19 October 2010 - 08:41 AM, said:

i get error on...

```For i As Integer = 0 To Racers.Count() - 1 Step 15
```

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

if you could help on this that would be brill

Kev

I will test it
Just I need to know what is the number of lines
in the first richtextbox (carlist)?
Perhaps need to check it on empty line before
and remove if this found in there

Reputation: 8
• Posts: 160
• Joined: 09-August 08

## Re: some advice on grouping numbers

Posted 19 October 2010 - 10:19 AM

i have tried it like

348,325,734,12,97,457,264,390,909

and also tried putting he numbers in like...

1
2
3
4
5
6
7
8

and so on

but both has the same outcome

Kev

### #15 fixo

• D.I.C Regular

Reputation: 83
• Posts: 335
• Joined: 10-May 09

## Re: some advice on grouping numbers

Posted 19 October 2010 - 10:44 AM

TADS, on 19 October 2010 - 09:19 AM, said:

i have tried it like

348,325,734,12,97,457,264,390,909

and also tried putting he numbers in like...

1
2
3
4
5
6
7
8

and so on

but both has the same outcome

Kev

Kev, can you try to load data by this way
(just for testing):
```    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lst As List(Of String) = New List(Of String)
Dim rnd = New Random()
For i As Integer = 0 To 99