Randomizing students in class

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

42 Replies - 2115 Views - Last Post: 31 October 2013 - 11:55 AM Rate Topic: -----

#16 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Randomizing students in class

Posted 11 October 2013 - 03:55 PM

So, analyzing that chunk of code here is my understanding of what's it doing, It gets a random number from 1 to 16, representing the students, that also range from 1 to 16.It removes that student from the class 1 list, that works as kind of a "available students" list. Now it prepares a string containing the 2 infos about the student that should be outputed : student number and class.finally the code outputs that, and repeats the whole process 8 times (0 to 7), once for each chair in the row. What I'm not getting is, if i remove th student from that available list how is the code still getting the same student. I'll try to look at your code and see the difference that makes this bug not happen.
Was This Post Helpful? 0
  • +
  • -

#17 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

Re: Randomizing students in class

Posted 11 October 2013 - 04:43 PM

That's not what it is doing.
OK let's this is the second time this section of code is used.
C1 has 8 students {8,9,10,11,12,13,14,15}
R1 has 8 students {0,1,2,3,4,5,6,7}
For R1L = 0 To 7
   Dim rstudent  = ran.Next(0, C1.Count)
   C1.RemoveAt(rstudent)
   R1.Add(String.Format("Student Nº{0} - Class 1001", rstudent))
   Console.WriteLine(R1.Item(R1L))
 Next


For each iteration of the loop, what are the values of variable used in the loop at each step of the iteration. Imaging the rstudent is zero every time.
Also answer the questions.
  • How many items (the count) are there in the list C1?
  • You pick a random number (not a student) R1 what number range can the random pick from?
  • You remove the student at position R1 in list C1
  • How many items (the count) are there in the list C1 now?
  • You add the format string which includes R1 to list R1
  • How many items (the count) are there in the list R1 now?
  • You output the item at index position R1L of list R1

What is the output?

This post has been edited by AdamSpeight2008: 11 October 2013 - 04:46 PM

Was This Post Helpful? 1
  • +
  • -

#18 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Randomizing students in class

Posted 11 October 2013 - 06:46 PM

So, aswering the questions:
1. C1 should have 16 students, and so should C2.
2. From 1 to 16 (Just found a mistake!). I think i didn't get something clear, the students don't have names, they are adressed by they'r number on the class list, IRL for exemple on my class I'm number 6 and there are 32 students, from 1 to 32.
3. Yes, because of what i explained in the previous question, removing the student and its position on the class list is the same.
4. 16, from 1 to 16.
5. I do?
R4.Add(String.Format("Student N{0} - Class 2001", rstudent))

6. 8? 0,1,2,3,4,5,6,7.
7. Yes
Was This Post Helpful? 0
  • +
  • -

#19 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

Re: Randomizing students in class

Posted 11 October 2013 - 07:06 PM

  • Wrong 8 students (I even told you that in the post.)
  • Wrong Range is 0 t0 7
  • Wrong Index isn't equal to ID, also would you be needing the idea?
  • Wrong 15 (You've removed one so it can't be the same)
  • Wrong You using the random index position not the student id.
  • Wrong 16, You've just inserted 8 items
  • Correct. But shouldn't the output be 8,9,10,11,12,13,14,15 cos that's the set of ids we worked with?

This post has been edited by AdamSpeight2008: 11 October 2013 - 07:09 PM

Was This Post Helpful? 1
  • +
  • -

#20 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Randomizing students in class

Posted 12 October 2013 - 06:10 PM

My god i feel like an idiot!
1. shouldn't it be correct, 32 students in the room, 2 classes, 32/2=16, C1 and C2. Why am i mistaken?
2. Because 8 is half of sixteen, 8 for each row?
3. I forgot that the student number is it's index plus 1(because index counts from 0)
4. Yeah.
5. Right, i forgot the +1!
6.
7. I didn't get what you sad here.
Well, even though this looks like my philosophy test score it's an awesome learning!
Was This Post Helpful? 0
  • +
  • -

#21 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

Re: Randomizing students in class

Posted 12 October 2013 - 06:12 PM

Look at post 17. Used the information in that post.

What if the IDs where characters and not integers
C1 = {i,j,k,l,m,n,o,p}
R1 = {a,b,c,d,e,f,g,h}

This post has been edited by AdamSpeight2008: 12 October 2013 - 06:15 PM

Was This Post Helpful? 1
  • +
  • -

#22 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Randomizing students in class

Posted 12 October 2013 - 06:41 PM

I get why my answers were all wrong! i didn't see those 2 lines!

Quote

C1 has 8 students {8,9,10,11,12,13,14,15}
R1 has 8 students {0,1,2,3,4,5,6,7}

That's why, i guess thats a consequence of 2am coding.
7. Yes, but in a randomic order.
Was This Post Helpful? 0
  • +
  • -

#23 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

Re: Randomizing students in class

Posted 12 October 2013 - 06:53 PM

I think you are still struggle with this concept that the INDEX <> ID.
What if the ID are letters and not numbers?

Imagine a bag of shopping (of 8 items), which you are unpacking.

This post has been edited by AdamSpeight2008: 12 October 2013 - 06:57 PM

Was This Post Helpful? 1
  • +
  • -

#24 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Randomizing students in class

Posted 12 October 2013 - 06:54 PM

If the id's were letters nothing would change, since RemoveAt refers to index rather than content, or id. Right?
Was This Post Helpful? 0
  • +
  • -

#25 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

Re: Randomizing students in class

Posted 12 October 2013 - 07:30 PM

Wrong.

Like I stated in my question post to make analysis simpler that rstudent=0 in each iteration of the loop.

If you did it properly you would see the following.
output ----------------------------------------------------+
R1  ------------------------------------+                  |
C1  -----------------+                  |                  |
rstudent  --------+  |                  |                  |
range  ---+       |  |                  |                  |
R1L -+    |       |  |                  |                  |
     |    |       |  |                  |                  |
     0    0 .. 7  0  {h,i,j,k,l,m,n,o}  {0              }  a
     1    0 .. 6  0  {i,j,k,l,m,n,o  }  {0,0            }  b
     2    0 .. 5  0  {j,k,l,m,n,o    }  {0,0,0          }  c
     3    0 .. 4  0  {k,l,m,n,o      }  {0,0,0,0        }  c
     4    0 .. 3  0  {l,m,n,o        }  {0,0,0,0,0      }  d
     5    0 .. 2  0  {m,n,o          }  {0,0,0,0,0,0    }  e
     6    0 .. 1  0  {n,o            }  {0,0,0,0,0,0,0  }  f
     7    0 .. 0  0  {o              }  {0,0,0,0,0,0,0,0}  g



See how the Index (RStudent and R1L) aren't the same as ID, which is in C1.

You need to use the ID referenced by the index position (RStudent)




Imagine a pack of cards, the index of the card in the deck isn't the same as the value of the card. Eg Card(25) = Ace Of Spaces : Card(13) = Seven of Diamonds

This post has been edited by AdamSpeight2008: 12 October 2013 - 07:31 PM

Was This Post Helpful? 2
  • +
  • -

#26 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Randomizing students in class

Posted 12 October 2013 - 07:43 PM

Hmm, i get it, is like if i have a pile of 8 books that i count from 0 to 7, if i want to refer to "Lord of The Rings" i shoul call it by its position on the pile, 5 lests say, rather than from its actual name. Did i get that right? So recalling my initial code
 For R1L As Int32 = 0 To 7
            Dim rstudent As Int32 = ran.Next(0, C1.Count)
            C1.RemoveAt(rstudent)
            R1.Add(String.Format("Student N{0} - Class 1001", rstudent + 1))
            Console.WriteLine(R1.Item(R1L))
        Next

The mistake would be that I'm adressing to C1's IDs rather then C1's Index values, right? This is quite confusing for me, but i feel like i got it, the thing is, how can i specify to C1 that i want its index values?
Was This Post Helpful? 0
  • +
  • -

#27 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

Re: Randomizing students in class

Posted 12 October 2013 - 08:01 PM

Still wrong.

Collections and Indexing them isn't that hard.

This post has been edited by AdamSpeight2008: 12 October 2013 - 08:03 PM

Was This Post Helpful? 0
  • +
  • -

#28 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Randomizing students in class

Posted 12 October 2013 - 08:05 PM

Aren't they already indexed by default? I'm reading about Collections, since I'm not sure what those are.
Was This Post Helpful? 0
  • +
  • -

#29 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,468
  • Joined: 29-May 08

Re: Randomizing students in class

Posted 12 October 2013 - 08:12 PM

Huh?
Was This Post Helpful? 0
  • +
  • -

#30 Raminator  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 283
  • Joined: 16-July 12

Re: Randomizing students in class

Posted 12 October 2013 - 08:39 PM

I did'nt see the still wrong part, then i really dont get this at all. I really am trying but i just dont get the difference between the ID of something in C1 to it's index. Because my example was, in my understanding very similar to yours. The ID of letter(4):"d" would be "d" and its index 4.Isn't that right?
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3