Click here to Skip to main content
15,894,312 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello i want to know how i can make a random seating arrangement for 20 students in a class in which no student has the same seat number in vb.net
Posted
Updated 21-Mar-12 2:00am
v2
Comments
[no name] 21-Mar-12 8:00am    
Sounds like homework.

What have you tried?
sherry1990 21-Mar-12 9:04am    
i made a list by dragging and dropping a list from the toolbox and filled it with integer values from (1-20)
a loop that will run 20 times is
for (int i=0;i<=20;i++)
ZurdoDev 21-Mar-12 8:18am    
What is the specific question?

1 solution

Only allow one student to sit on each seat. Problem solved.


As this is your homework, I won't give you code. However, how I would do it:
Create a List of seat numbers, populate it with numbers in ascending order.
Create a Random variable, and run a loop.
Inside the loop, generate a random number with a maximum of the number of elements in the List.
Get the value for the set number at that location - that is where the student will sit.
Remove the element from the list, using List.RemoveAt
Repeat while there are elements in the list.
 
Share this answer
 
Comments
sherry1990 21-Mar-12 8:51am    
hello i tried this:
<pre lang="vb">

Dim x as integer
Dim rd as new Random
for(x=1;x>0:x++)
x=rd.Next(1,21)


</pre>
i am having trouble with this part:
Get the value for the set number at that location - that is where the student will sit.
Remove the element from the list, using List.RemoveAt
Repeat while there are elements in the list.
OriginalGriff 21-Mar-12 8:55am    
Ok, that code won't work at all - as you probably know since you will have tried to execute it.

Do you know how to set up a List of integers?
Do you know how to add things to the list?
Do you know how a create a loop which will run twenty times?
sherry1990 21-Mar-12 9:01am    
yes i know how to make a list we just drag and drop a list from the toolbox and fill it with integer values from (1-20)
a loop that will run 20 times is
for (int i=0;i<=20;i++)
OriginalGriff 21-Mar-12 9:09am    
Well, you want to make the list programatically - in code instead of by drag and drop:

Dim availableSeats As New List(Of Integer)()

Your "for" loop won't work in VB either - assuming the ':' is supposed to be a ';' that is a C, C++ or C# loop construct.

For i As Integer = 0 To 19
availableSeats.Add(i)
Next

Will give you a list of twenty available seats.
Now try the next part.
sherry1990 21-Mar-12 9:19am    
hello i tried it but
it gave me an error :
that "add" is not a member of "System.Windows.Forms.Listbox" what should i do?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900