some advice on grouping numbers

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 1144 Views - Last Post: 21 October 2010 - 03:45 AM Rate Topic: -----

#1 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • 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  Icon User is online

  • 4+1=Moo
  • member icon

Reputation: 146
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#3 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • 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

thanks for the reply

Kev
Was This Post Helpful? 0
  • +
  • -

#4 fixo  Icon User is offline

  • D.I.C Regular

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

Re: some advice on grouping numbers

Posted 17 October 2010 - 01:37 AM

View PostTADS, 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

thanks for the reply

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
                    group.Add(numbers(i))
                Next
                groups.Add(group)
            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'~
Was This Post Helpful? 1
  • +
  • -

#5 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#6 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#7 fixo  Icon User is offline

  • D.I.C Regular

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

Re: some advice on grouping numbers

Posted 18 October 2010 - 01:51 PM

View PostTADS, 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'~
Was This Post Helpful? 0
  • +
  • -

#8 TADS  Icon User is offline

  • D.I.C Head
  • member icon

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

Re: some advice on grouping numbers

Posted 18 October 2010 - 02:00 PM

ok thanks for the help :)
Was This Post Helpful? 0
  • +
  • -

#9 fixo  Icon User is offline

  • D.I.C Regular

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

Re: some advice on grouping numbers

Posted 18 October 2010 - 02:41 PM

View PostTADS, 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
                group.Add(Racers(i).Racer)
                line = line & vbTab & Racers(i).Racer
            Next
            dispGrous.Add(line)
            groups.Add(group)
        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'~
Was This Post Helpful? 1
  • +
  • -

#10 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • 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 :)
Was This Post Helpful? 0
  • +
  • -

#11 fixo  Icon User is offline

  • D.I.C Regular

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

Re: some advice on grouping numbers

Posted 19 October 2010 - 05:17 AM

View PostTADS, 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'~
Was This Post Helpful? 0
  • +
  • -

#12 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • 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
                group.Add(Racers(i).Racer)
                line = line & vbTab & Racers(i).Racer
            Next
            dispGrous.Add(line)
            groups.Add(group)
        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
Was This Post Helpful? 0
  • +
  • -

#13 fixo  Icon User is offline

  • D.I.C Regular

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

Re: some advice on grouping numbers

Posted 19 October 2010 - 09:57 AM

View PostTADS, 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
Was This Post Helpful? 0
  • +
  • -

#14 TADS  Icon User is offline

  • D.I.C Head
  • member icon

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

Re: some advice on grouping numbers

Posted 19 October 2010 - 10:19 AM

Thanks for the quick reply...

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
Was This Post Helpful? 0
  • +
  • -

#15 fixo  Icon User is offline

  • D.I.C Regular

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

Re: some advice on grouping numbers

Posted 19 October 2010 - 10:44 AM

View PostTADS, on 19 October 2010 - 09:19 AM, said:

Thanks for the quick reply...

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
            lst.Add(rnd.Next(500, 900))
        Next

        Me.carlist.Lines = lst.ToArray()  
 End Sub

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2