jeudi 14 janvier 2016

Distributing k books into n slots in a random manner

Let's say that I have k in total books. For example, k=100. I want to write a program in Java that puts x books (0 < x < k) in n different slots (n < k) (nodes of ArrayList).

The x number will be a random number in the [0...5] range. If x=4, then the new k would be: k = k-x. Each slot should have [0...5] books. The sum of books from every slot should equal to k. The problem is that sometimes the sum can exceed k.




Aucun commentaire:

Enregistrer un commentaire