1

I have created a simple algorithm to solve a bin packing problem. To test it properly I need to create lots of box objects of various sizes (different lengths and widths). I have a box object: public Box(int width, int height) How would I create say 500 boxes without hard coding them of different sizes and store them in an ArrayList?

Thank you for your help

Nick
  • 135
  • 1
  • 1
  • 11

1 Answers1

2

Use the Random class, perhaps with a factory method:

public static Box create(int minWidth, int maxWidth, int minHeight, int maxHeight) {
    Random random = Random();
    return new Box(minWidth + random.nextInt(maxWidth - minWidth), minHeight+ random.nextInt(maxHeight - minHeight));
}
Bohemian
  • 412,405
  • 93
  • 575
  • 722