Random class - assign an object to another object

It’s hard for me to understand this class, and everything that I saw did not help. I will try to make my question as simple as possible.

If I have examiner 1, examiner 2, examiner 3 and route 1, route 2, route 3.

Both are strings.

How would I accidentally assign an examiner to a route? This is probably a stupid question, but I just can't wrap my head around it.

+4
source share
3 answers

Put the examiners on the List and use Collections.shuffle () to shuffle it.

After it is shuffled, listOfExaminers.get(i) will be assigned to the corresponding route [You can also put routes on the list - to make it as general as possible, but you only need to shuffle one list].

+3
source

You can save all 3 examiners and all 3 routes in 2 different String arrays, and then use the map to store the Examiner-Route combination. You can then use the Random class to randomly assign a route to a given examiner.

+2
source

Create a List<String> containing the examiners and a List<String> containing the routes. Shuffle the list of routes (using Collections.shuffle () ).

Now the examiner with index i is associated with a randomly selected route with index i . You can, of course, create an Examination class containing the examiner and the corresponding route, and create an instance of this class for each pair.

0
source

Source: https://habr.com/ru/post/1397436/


All Articles