private int pickFruit(float[] currentFruits) {
    // generate a prefix sum
    float[] prefixsum = new float[NUM_FRUIT_TYPES];
    prefixsum[0] = currentFruits[0];
    for (int i = 1; i != NUM_FRUIT_TYPES; ++i) {
      prefixsum[i] = prefixsum[i-1] + currentFruits[i];
    }

    float currentFruitCount = prefixsum[NUM_FRUIT_TYPES - 1];
    // roll a dice [0, currentFruitCount)
    int rnd = random.nextInt((int) currentFruitCount);
        
    for (int i = 0; i != NUM_FRUIT_TYPES; ++i)
      if (rnd < prefixsum[i])
        return i;

    assert false;

    return -1;
  }