Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to balanced number in java model

Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I know the title means nothing, but what i want is, e.g. :

Given I have three sets. They have the same size (e.g. 100, indeed the size is not important). I want to get 100 objects from the three sets, but the number of each set needs to be close, e.g. set1 33, set2 33 and set3 34.

Is there any mathematical model can achieve above scenario?

Posts: 3648
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not thinking about the numbers for the moment.

Given x objects and you want y sets. So each set should have round(x/y) objects (call this z), correct?

Now the question is, do you just need this z number or do you want to so-called even distribute the x objects into the y sets "based on some attribute"?

The latter one would utilize the object's hash code to determine which set the object will fall into.
lowercase baba
Posts: 12893
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
psuedo code

It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic