code: public static List<SecretShare> split(BigInteger secret, BigInteger[] coefficients, int total, int threshold,
              BigInteger prime) {
  
          if (secret.compareTo(BigInteger.ZERO) <= 0) {
              throw new IllegalArgumentException("secret must be positive integer");
          }
  
          if (prime.compareTo(secret) <= 0) {
              throw new IllegalArgumentException("prime must be greater than secret");
          }
  
          if (coefficients.length < threshold) {
              throw new IllegalArgumentException("not enough coefficients, need " + threshold + ", have " +
                      coefficients.length);
          }
  
          if (total < threshold) {
              throw new IllegalArgumentException("total number of shares must be greater than or equal threshold");
          }
  
          List<SecretShare> shares = new ArrayList<>();
  
          for (int i = 1; i <= total; i++) {
              BigInteger x = BigInteger.valueOf(i);
              BigInteger v = coefficients[0];
              for (int c = 1; c < threshold; c++) {
                  v = v.add(x.modPow(BigInteger.valueOf(c), prime).multiply(coefficients[c]).mod(prime)).mod(prime);
              }
              shares.add(new SecretShare(i, v, prime));
          }
          return shares;
      }
docs: Split the secret into the specified total number of shares. Specified minimum threshold of shares will need to be
  present in order to join them back into the secret.
  
  @param secret number to split into shares
  @param coefficients random coefficients of the underlying polynomial
  @param total number of shares to generate
  @param threshold minimum number of shares required to successfully join back the secret
  @param prime to be used for finite field arithmetic
  @return list of shares